Boost logo

Boost :

Subject: [boost] BOOST_EXPLICIT_OPERATOR_BOOL macro?
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2010-04-21 11:16:42


Hi,

IIUC, c+0x allows the safe bool idiom to be implemented as

explicit operator bool() const { ...}

but in c+03 emulating that behaviour is a bit messy.

There appears to be a solution for c+03 in
boost/smart_ptr/detail/operator_bool.hpp, but it's targeted for the
smart_ptr classes only.

Would it be possible to extract operator_bool.hpp into a reusable macro,
something like:

#include <boost/utility/operator_bool.hpp>
struct some
{
  BOOST_EXPLICIT_OPERATOR_BOOL( m_value != 0; )

 int m_value;
};

What do you think?

Cheers,
Christian


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