Boost logo

Boost :

From: Sam Partington (Sam.Partington_at_[hidden])
Date: 2003-02-25 07:01:31


While making myself an interim shared_resource class, I found myself reusing
the shared_ptr safe-bool conversion, and thought that really the idiom ought
to go into the operators library.

I am unsure about the name, but for now bool_testable seems to match the
naming style used by the rest of operators, and be reasonably clear about
its intent. Any suggestions gratefully received

Essentially you supply a operator! and it supplies an unspecified-bool-type
conversion operator.

 //T: primary operand type
 //t: values of type T

 // Template Supplied Operations Requirements
 // bool_testable<T> operator unspecified-bool-type() !t

 template <class T, class B = ::boost::detail::empty_base> struct
bool_testable : B
  void safe_bool_conversion() const { }

  typedef void (bool_testable<T, B>::*unspecified_bool_type)() const;
  operator unspecified_bool_type() const
   return !static_cast<const T&>(*this) ? 0 : &bool_testable<T,

Any problems with this?


Boost list run by bdawes at, gregod at, cpdaniel at, john at