Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-02-26 08:27:29

Sam Partington wrote:
> Daniel Frey wrote:
> > I also think it would be fair to mention Dave as a contributor, too,
> > as he provided the way to reduce the overhead.
> Of course, that bit was still there from the first time through, also
> whoever came up with the original "unspecified-bool-type" idiom needs
> acknowledged as well. No offence intended, merely laziness. Sorry.

No problem. IIRC it was Peter Dimov who came up with the safe-bool idiom
first. At least I saw it first from him. Another way which works but
results in worse error messages is this:

template <class T, class B = ::boost::detail::empty_base>
struct bool_testable : B
  operator int() const;

  operator bool() const
    return !!static_cast< T& >( *this );

It should be a more efficient implementation for most of the points Dave
mentioned and it should also work in all cases (allowing the use as a
bool, int is private, thus not accessible and other conversions, e.g. to
'long' are ambiguous. The drawback is, that the error messages are not
as clear and obvious as for Peter's idiom.

> David Abrahams wrote:
> > It's very nice, but you left out the most-important parts: patches
> > for the docs and testsuite.


Regards, Daniel

Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web:

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