Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:29

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2013.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 
0008 /*!
0009  * \file   explicit_operator_bool.hpp
0010  * \author Andrey Semashev
0011  * \date   08.03.2009
0012  *
0013  * This header defines a compatibility macro that implements an unspecified
0014  * \c bool operator idiom, which is superseded with explicit conversion operators in
0015  * C++11.
0016  */
0017 
0018 #ifndef BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP
0019 #define BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP
0020 
0021 #include <boost/config.hpp>
0022 #include <boost/config/workaround.hpp>
0023 
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027 
0028 #if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
0029 
0030 /*!
0031  * \brief The macro defines an explicit operator of conversion to \c bool
0032  *
0033  * The macro should be used inside the definition of a class that has to
0034  * support the conversion. The class should also implement <tt>operator!</tt>,
0035  * in terms of which the conversion operator will be implemented.
0036  */
0037 #define BOOST_EXPLICIT_OPERATOR_BOOL()\
0038     BOOST_FORCEINLINE explicit operator bool () const\
0039     {\
0040         return !this->operator! ();\
0041     }
0042 
0043 /*!
0044  * \brief The macro defines a noexcept explicit operator of conversion to \c bool
0045  *
0046  * The macro should be used inside the definition of a class that has to
0047  * support the conversion. The class should also implement <tt>operator!</tt>,
0048  * in terms of which the conversion operator will be implemented.
0049  */
0050 #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
0051     BOOST_FORCEINLINE explicit operator bool () const BOOST_NOEXCEPT\
0052     {\
0053         return !this->operator! ();\
0054     }
0055 
0056 #if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
0057 
0058 /*!
0059  * \brief The macro defines a constexpr explicit operator of conversion to \c bool
0060  *
0061  * The macro should be used inside the definition of a class that has to
0062  * support the conversion. The class should also implement <tt>operator!</tt>,
0063  * in terms of which the conversion operator will be implemented.
0064  */
0065 #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
0066     BOOST_FORCEINLINE BOOST_CONSTEXPR explicit operator bool () const BOOST_NOEXCEPT\
0067     {\
0068         return !this->operator! ();\
0069     }
0070 
0071 #else
0072 
0073 #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
0074 
0075 #endif
0076 
0077 #else // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
0078 
0079 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG)
0080 // Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
0081 #define BOOST_NO_UNSPECIFIED_BOOL
0082 #endif // (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG)
0083 
0084 #if !defined(BOOST_NO_UNSPECIFIED_BOOL)
0085 
0086 namespace boost {
0087 
0088 namespace detail {
0089 
0090 #if !defined(_MSC_VER) && !defined(__IBMCPP__)
0091 
0092     struct unspecified_bool
0093     {
0094         // NOTE TO THE USER: If you see this in error messages then you tried
0095         // to apply an unsupported operator on the object that supports
0096         // explicit conversion to bool.
0097         struct OPERATORS_NOT_ALLOWED;
0098         static void true_value(OPERATORS_NOT_ALLOWED*) {}
0099     };
0100     typedef void (*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*);
0101 
0102 #else
0103 
0104     // MSVC and VACPP are too eager to convert pointer to function to void* even though they shouldn't
0105     struct unspecified_bool
0106     {
0107         // NOTE TO THE USER: If you see this in error messages then you tried
0108         // to apply an unsupported operator on the object that supports
0109         // explicit conversion to bool.
0110         struct OPERATORS_NOT_ALLOWED;
0111         void true_value(OPERATORS_NOT_ALLOWED*) {}
0112     };
0113     typedef void (unspecified_bool::*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*);
0114 
0115 #endif
0116 
0117 } // namespace detail
0118 
0119 } // namespace boost
0120 
0121 #define BOOST_EXPLICIT_OPERATOR_BOOL()\
0122     BOOST_FORCEINLINE operator boost::detail::unspecified_bool_type () const\
0123     {\
0124         return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\
0125     }
0126 
0127 #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
0128     BOOST_FORCEINLINE operator boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\
0129     {\
0130         return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\
0131     }
0132 
0133 #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
0134     BOOST_FORCEINLINE BOOST_CONSTEXPR operator boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\
0135     {\
0136         return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\
0137     }
0138 
0139 #else // !defined(BOOST_NO_UNSPECIFIED_BOOL)
0140 
0141 #define BOOST_EXPLICIT_OPERATOR_BOOL()\
0142     BOOST_FORCEINLINE operator bool () const\
0143     {\
0144         return !this->operator! ();\
0145     }
0146 
0147 #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
0148     BOOST_FORCEINLINE operator bool () const BOOST_NOEXCEPT\
0149     {\
0150         return !this->operator! ();\
0151     }
0152 
0153 #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
0154     BOOST_FORCEINLINE BOOST_CONSTEXPR operator bool () const BOOST_NOEXCEPT\
0155     {\
0156         return !this->operator! ();\
0157     }
0158 
0159 #endif // !defined(BOOST_NO_UNSPECIFIED_BOOL)
0160 
0161 #endif // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
0162 
0163 #endif // BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP