1 
2 #ifndef BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL_HPP_
3 #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL_HPP_
4 
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
9 
10 #include <boost/contract/detail/name.hpp>
11 #include <boost/config.hpp>
12 #include <boost/detail/workaround.hpp>
13 
14 // NOTE: This code is inspired by <boost/shared_ptr/detail/operator_bool.hpp>.
15 
16 /* PRIVATE */
17 
18 // operator! is redundant, but some compilers need it.
19 #define BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) \
20     bool operator!() const BOOST_NOEXCEPT { return !(bool_expr); }
21 
22 /* PUBLIC */
23 
24 #if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) && \
25         !defined(BOOST_NO_CXX11_NULLPTR)
26     #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \
27         explicit operator bool() const BOOST_NOEXCEPT { return (bool_expr); } \
28         BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr)
29 #elif (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || \
30         defined(__CINT__)
31     #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \
32         operator bool() const BOOST_NOEXCEPT { return (bool_expr); } \
33         BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr)
34 #elif defined(_MANAGED)
35     #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \
36         static void BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func)( \
37                 this_type***) {} \
38         typedef void (*BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type))( \
39                 this_type***); \
40         operator BOOST_CONTRACT_DETAIL_NANE(operator_safe_bool_type)() \
41                 const BOOST_NOEXCEPT { \
42             return (bool_expr) ? \
43                     &BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func) : 0; \
44         } \
45         BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr)
46 #elif (defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200)) || \
47         (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304)) || \
48         (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590))
49     #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \
50         void BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func)() const {} \
51         typedef void (this_type::*BOOST_CONTRACT_DETAIL_NAME1( \
52                 operator_safe_bool_type))() const; \
53         operator BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type)() \
54                 const BOOST_NOEXCEPT { \
55             return (bool_expr) ? &this_type:: \
56                     BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func) : 0; \
57         } \
58         BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr)
59 #else
60     #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \
61         void* BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_data); \
62         typedef void* this_type::*BOOST_CONTRACT_DETAIL_NAME1( \
63                 operator_safe_bool_type);\
64         operator BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type)() \
65                 const BOOST_NOEXCEPT { \
66             return (bool_expr) ? &this_type:: \
67                     BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_data) : 0; \
68         } \
69         BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr)
70 #endif
71 
72 #endif // #include guard
73 
74