BVB Source Codes

mars Show explicit_operator_bool.hpp Source code

Return Download mars: download explicit_operator_bool.hpp Source code - Download mars Source code - Type:.hpp
  1. /*
  2.  *          Copyright Andrey Semashev 2007 - 2013.
  3.  * Distributed under the Boost Software License, Version 1.0.
  4.  *    (See accompanying file LICENSE_1_0.txt or copy at
  5.  *          http://www.boost.org/LICENSE_1_0.txt)
  6.  */
  7.  
  8. /*!
  9.  * \file   explicit_operator_bool.hpp
  10.  * \author Andrey Semashev
  11.  * \date   08.03.2009
  12.  *
  13.  * This header defines a compatibility macro that implements an unspecified
  14.  * \c bool operator idiom, which is superseded with explicit conversion operators in
  15.  * C++11.
  16.  */
  17.  
  18. #ifndef BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP
  19. #define BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP
  20.  
  21. #include <boost/config.hpp>
  22.  
  23. #ifdef BOOST_HAS_PRAGMA_ONCE
  24. #pragma once
  25. #endif
  26.  
  27. #if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  28.  
  29. /*!
  30.  * \brief The macro defines an explicit operator of conversion to \c bool
  31.  *
  32.  * The macro should be used inside the definition of a class that has to
  33.  * support the conversion. The class should also implement <tt>operator!</tt>,
  34.  * in terms of which the conversion operator will be implemented.
  35.  */
  36. #define BOOST_EXPLICIT_OPERATOR_BOOL()\
  37.     BOOST_FORCEINLINE explicit operator bool () const\
  38.     {\
  39.         return !this->operator! ();\
  40.     }
  41.  
  42. /*!
  43.  * \brief The macro defines a noexcept explicit operator of conversion to \c bool
  44.  *
  45.  * The macro should be used inside the definition of a class that has to
  46.  * support the conversion. The class should also implement <tt>operator!</tt>,
  47.  * in terms of which the conversion operator will be implemented.
  48.  */
  49. #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
  50.     BOOST_FORCEINLINE explicit operator bool () const BOOST_NOEXCEPT\
  51.     {\
  52.         return !this->operator! ();\
  53.     }
  54.  
  55. /*!
  56.  * \brief The macro defines a constexpr explicit operator of conversion to \c bool
  57.  *
  58.  * The macro should be used inside the definition of a class that has to
  59.  * support the conversion. The class should also implement <tt>operator!</tt>,
  60.  * in terms of which the conversion operator will be implemented.
  61.  */
  62. #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
  63.     BOOST_FORCEINLINE BOOST_CONSTEXPR explicit operator bool () const BOOST_NOEXCEPT\
  64.     {\
  65.         return !this->operator! ();\
  66.     }
  67.  
  68. #else // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  69.  
  70. #if (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG)
  71. // Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
  72. #define BOOST_NO_UNSPECIFIED_BOOL
  73. #endif // (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG)
  74.  
  75. #if !defined(BOOST_NO_UNSPECIFIED_BOOL)
  76.  
  77. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  78.  
  79. namespace detail {
  80.  
  81. #if !defined(_MSC_VER) && !defined(__IBMCPP__)
  82.  
  83.     struct unspecified_bool
  84.     {
  85.         // NOTE TO THE USER: If you see this in error messages then you tried
  86.         // to apply an unsupported operator on the object that supports
  87.         // explicit conversion to bool.
  88.         struct OPERATORS_NOT_ALLOWED;
  89.         static void true_value(OPERATORS_NOT_ALLOWED*) {}
  90.     };
  91.     typedef void (*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*);
  92.  
  93. #else
  94.  
  95.     // MSVC and VACPP are too eager to convert pointer to function to void* even though they shouldn't
  96.     struct unspecified_bool
  97.     {
  98.         // NOTE TO THE USER: If you see this in error messages then you tried
  99.         // to apply an unsupported operator on the object that supports
  100.         // explicit conversion to bool.
  101.         struct OPERATORS_NOT_ALLOWED;
  102.         void true_value(OPERATORS_NOT_ALLOWED*) {}
  103.     };
  104.     typedef void (unspecified_bool::*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*);
  105.  
  106. #endif
  107.  
  108. } // namespace detail
  109.  
  110. } // namespace mars_boost
  111.  
  112. #define BOOST_EXPLICIT_OPERATOR_BOOL()\
  113.     BOOST_FORCEINLINE operator mars_boost::detail::unspecified_bool_type () const\
  114.     {\
  115.         return (!this->operator! () ? &mars_boost::detail::unspecified_bool::true_value : (mars_boost::detail::unspecified_bool_type)0);\
  116.     }
  117.  
  118. #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
  119.     BOOST_FORCEINLINE operator mars_boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\
  120.     {\
  121.         return (!this->operator! () ? &mars_boost::detail::unspecified_bool::true_value : (mars_boost::detail::unspecified_bool_type)0);\
  122.     }
  123.  
  124. #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
  125.     BOOST_FORCEINLINE BOOST_CONSTEXPR operator mars_boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\
  126.     {\
  127.         return (!this->operator! () ? &mars_boost::detail::unspecified_bool::true_value : (mars_boost::detail::unspecified_bool_type)0);\
  128.     }
  129.  
  130. #else // !defined(BOOST_NO_UNSPECIFIED_BOOL)
  131.  
  132. #define BOOST_EXPLICIT_OPERATOR_BOOL()\
  133.     BOOST_FORCEINLINE operator bool () const\
  134.     {\
  135.         return !this->operator! ();\
  136.     }
  137.  
  138. #define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\
  139.     BOOST_FORCEINLINE operator bool () const BOOST_NOEXCEPT\
  140.     {\
  141.         return !this->operator! ();\
  142.     }
  143.  
  144. #define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\
  145.     BOOST_FORCEINLINE BOOST_CONSTEXPR operator bool () const BOOST_NOEXCEPT\
  146.     {\
  147.         return !this->operator! ();\
  148.     }
  149.  
  150. #endif // !defined(BOOST_NO_UNSPECIFIED_BOOL)
  151.  
  152. #endif // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  153.  
  154. #endif // BOOST_CORE_EXPLICIT_OPERATOR_BOOL_HPP
  155.  
downloadexplicit_operator_bool.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top