Chris@16: // This header intentionally has no include guards. Chris@16: // Chris@16: // Copyright (c) 2010 Neil Groves Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt Chris@16: // Chris@16: // This code utilises the experience gained during the evolution of Chris@16: // Chris@16: #ifndef BOOST_RANGE_SAFE_BOOL_INCLUDED_HPP Chris@16: #define BOOST_RANGE_SAFE_BOOL_INCLUDED_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace range_detail Chris@16: { Chris@16: Chris@16: template Chris@16: class safe_bool Chris@16: { Chris@16: public: Chris@16: typedef safe_bool this_type; Chris@16: Chris@16: #if (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570)) || defined(__CINT_) Chris@16: typedef bool unspecified_bool_type; Chris@16: static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) Chris@16: { Chris@16: return x; Chris@16: } Chris@16: #elif defined(_MANAGED) Chris@16: static void unspecified_bool(this_type***) Chris@16: { Chris@16: } Chris@16: typedef void(*unspecified_bool_type)(this_type***); Chris@16: static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) Chris@16: { Chris@16: return x ? unspecified_bool : 0; Chris@16: } Chris@16: #elif \ Chris@16: ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ Chris@16: ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \ Chris@16: ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) ) Chris@16: Chris@16: typedef bool (this_type::*unspecified_bool_type)() const; Chris@16: Chris@16: static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr) Chris@16: { Chris@16: return x ? &this_type::detail_safe_bool_member_fn : 0; Chris@16: } Chris@16: private: Chris@16: bool detail_safe_bool_member_fn() const { return false; } Chris@16: #else Chris@16: typedef DataMemberPtr unspecified_bool_type; Chris@16: static unspecified_bool_type to_unspecified_bool(const bool x, DataMemberPtr p) Chris@16: { Chris@16: return x ? p : 0; Chris@16: } Chris@16: #endif Chris@16: private: Chris@16: safe_bool(); Chris@16: safe_bool(const safe_bool&); Chris@16: void operator=(const safe_bool&); Chris@16: ~safe_bool(); Chris@16: }; Chris@16: Chris@16: } // namespace range_detail Chris@16: } // namespace boost Chris@16: Chris@16: #endif // include guard