Boost logo

Boost :

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


Hi,

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.

 //Key
 //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
 {
 private:
  void safe_bool_conversion() const { }
 public:

  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,
B>::safe_bool_conversion;
  }
 };

Any problems with this?

Sam


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk