operator_bool.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This header intentionally has no include guards.
  2. //
  3. // Copyright (c) 2001-2009, 2012 Peter Dimov
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt
  8. #if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )
  9. explicit operator bool () const BOOST_NOEXCEPT
  10. {
  11. return px != 0;
  12. }
  13. #elif ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
  14. operator bool () const BOOST_NOEXCEPT
  15. {
  16. return px != 0;
  17. }
  18. #elif defined( _MANAGED )
  19. static void unspecified_bool( this_type*** )
  20. {
  21. }
  22. typedef void (*unspecified_bool_type)( this_type*** );
  23. operator unspecified_bool_type() const BOOST_NOEXCEPT
  24. {
  25. return px == 0? 0: unspecified_bool;
  26. }
  27. #elif \
  28. ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
  29. ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
  30. ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
  31. typedef element_type * (this_type::*unspecified_bool_type)() const;
  32. operator unspecified_bool_type() const BOOST_NOEXCEPT
  33. {
  34. return px == 0? 0: &this_type::get;
  35. }
  36. #else
  37. typedef element_type * this_type::*unspecified_bool_type;
  38. operator unspecified_bool_type() const BOOST_NOEXCEPT
  39. {
  40. return px == 0? 0: &this_type::px;
  41. }
  42. #endif
  43. // operator! is redundant, but some compilers need it
  44. bool operator! () const BOOST_NOEXCEPT
  45. {
  46. return px == 0;
  47. }