operator_bool.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This header intentionally has no include guards.
  2. //
  3. // Copyright (c) 2001-2009 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(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
  9. operator bool () const
  10. {
  11. return px != 0;
  12. }
  13. #elif defined( _MANAGED )
  14. static void unspecified_bool( this_type*** )
  15. {
  16. }
  17. typedef void (*unspecified_bool_type)( this_type*** );
  18. operator unspecified_bool_type() const // never throws
  19. {
  20. return px == 0? 0: unspecified_bool;
  21. }
  22. #elif \
  23. ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
  24. ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
  25. ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
  26. typedef T * (this_type::*unspecified_bool_type)() const;
  27. operator unspecified_bool_type() const // never throws
  28. {
  29. return px == 0? 0: &this_type::get;
  30. }
  31. #else
  32. typedef T * this_type::*unspecified_bool_type;
  33. operator unspecified_bool_type() const // never throws
  34. {
  35. return px == 0? 0: &this_type::px;
  36. }
  37. #endif
  38. // operator! is redundant, but some compilers need it
  39. bool operator! () const // never throws
  40. {
  41. return px == 0;
  42. }