Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | // <ndnboost/smart_ptr/operator_bool.hpp> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 10 | #ifndef NDNBOOST_RANGE_SAFE_BOOL_INCLUDED_HPP |
| 11 | #define NDNBOOST_RANGE_SAFE_BOOL_INCLUDED_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 12 | |
| 13 | #include <ndnboost/config.hpp> |
| 14 | #include <ndnboost/range/config.hpp> |
| 15 | |
| 16 | namespace ndnboost |
| 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 27 | #if (defined(__SUNPRO_CC) && NDNBOOST_WORKAROUND(__SUNPRO_CC, < 0x570)) || defined(__CINT_) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 43 | ( defined(__MWERKS__) && NDNBOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 44 | ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 45 | ( defined(__SUNPRO_CC) && NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 ndnboost |
| 71 | |
| 72 | #endif // include guard |