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