operator_bool.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. && !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
  10. explicit operator bool () const BOOST_SP_NOEXCEPT
  11. {
  12. return px != 0;
  13. }
  14. #elif ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
  15. operator bool () const BOOST_SP_NOEXCEPT
  16. {
  17. return px != 0;
  18. }
  19. #elif defined( _MANAGED )
  20. static void unspecified_bool( this_type*** )
  21. {
  22. }
  23. typedef void (*unspecified_bool_type)( this_type*** );
  24. operator unspecified_bool_type() const BOOST_SP_NOEXCEPT
  25. {
  26. return px == 0? 0: unspecified_bool;
  27. }
  28. #elif \
  29. ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
  30. ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
  31. ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
  32. typedef element_type * (this_type::*unspecified_bool_type)() const;
  33. operator unspecified_bool_type() const BOOST_SP_NOEXCEPT
  34. {
  35. return px == 0? 0: &this_type::get;
  36. }
  37. #else
  38. typedef element_type * this_type::*unspecified_bool_type;
  39. operator unspecified_bool_type() const BOOST_SP_NOEXCEPT
  40. {
  41. return px == 0? 0: &this_type::px;
  42. }
  43. #endif
  44. // operator! is redundant, but some compilers need it
  45. bool operator! () const BOOST_SP_NOEXCEPT
  46. {
  47. return px == 0;
  48. }