1 // This header intentionally has no include guards. 2 // 3 // Copyright (c) 2010 Neil Groves 4 // Distributed under the Boost Software License, Version 1.0. 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 // This code utilises the experience gained during the evolution of 9 // <boost/smart_ptr/operator_bool.hpp> 10 #ifndef BOOST_RANGE_SAFE_BOOL_INCLUDED_HPP 11 #define BOOST_RANGE_SAFE_BOOL_INCLUDED_HPP 12 13 #include <boost/config.hpp> 14 #include <boost/range/config.hpp> 15 16 namespace boost 17 { 18 namespace range_detail 19 { 20 21 template<class DataMemberPtr> 22 class safe_bool 23 { 24 public: 25 typedef safe_bool this_type; 26 27 #if (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570)) || defined(__CINT_) 28 typedef bool unspecified_bool_type; 29 static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) 30 { 31 return x; 32 } 33 #elif defined(_MANAGED) 34 static void unspecified_bool(this_type***) 35 { 36 } 37 typedef void(*unspecified_bool_type)(this_type***); 38 static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) 39 { 40 return x ? unspecified_bool : 0; 41 } 42 #elif \ 43 ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ 44 ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \ 45 ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) ) 46 47 typedef bool (this_type::*unspecified_bool_type)() const; 48 49 static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) 50 { 51 return x ? &this_type::detail_safe_bool_member_fn : 0; 52 } 53 private: 54 bool detail_safe_bool_member_fn() const { return false; } 55 #else 56 typedef DataMemberPtr unspecified_bool_type; 57 static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr p) 58 { 59 return x ? p : 0; 60 } 61 #endif 62 private: 63 safe_bool(); 64 safe_bool(const safe_bool&); 65 void operator=(const safe_bool&); 66 ~safe_bool(); 67 }; 68 69 } // namespace range_detail 70 } // namespace boost 71 72 #endif // include guard 73