blob: c5a073120f06c039120c88d7299915eeda6957b9 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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 Thompson3d613fd2013-10-15 15:39:04 -070010#ifndef NDNBOOST_RANGE_SAFE_BOOL_INCLUDED_HPP
11#define NDNBOOST_RANGE_SAFE_BOOL_INCLUDED_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070012
13#include <ndnboost/config.hpp>
14#include <ndnboost/range/config.hpp>
15
16namespace ndnboost
17{
18 namespace range_detail
19 {
20
21template<class DataMemberPtr>
22class safe_bool
23{
24public:
25 typedef safe_bool this_type;
26
Jeff Thompson3d613fd2013-10-15 15:39:04 -070027#if (defined(__SUNPRO_CC) && NDNBOOST_WORKAROUND(__SUNPRO_CC, < 0x570)) || defined(__CINT_)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070028 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 Thompson3d613fd2013-10-15 15:39:04 -070043 ( defined(__MWERKS__) && NDNBOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070044 ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045 ( defined(__SUNPRO_CC) && NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070046
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 }
53private:
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
62private:
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