Boost logo

Boost :

From: Sam Partington (sam.partington_at_[hidden])
Date: 2003-11-27 06:11:48


Daryle Walker <mailto:darylew_at_[hidden]> wrote:

> Note that now the core routines are defined as:
> 1. (In)equality
> 2. Default construction
> 2a. The default state must have semantics that map to FALSE and be
> the _sole_ state that does this

Personally, I don't like the requirements that the type must be default
constructible, and that it must provide a suitable operator!=. I often have
types that arn't comparable, but _do_ have bool convertible semantics.

And the interface is messy and won't compile :

class A : public boolean_conversion<A, int (A::*)(), &A::dummy>

You're not allowed an incomplete type here.

Theres no need for the user to provide the boolean conversion type and a
member. If the user provides operator!, then we can use that as the boolean
type, and we can also provide a private, undefined operator== and operator!=
to prevent poisoning of those operators. If the user provides their own
then the private ones will never be called - no problem :

template <class T, class B = ::boost::detail::empty_base>
        struct safe_bool : B
{
        typedef bool (T::*safe_bool_type)() const;

        operator safe_bool_type() const { return !static_cast<const
T&>(*this) ? 0 : &T::operator!; }
private:
        bool operator!=(const safe_bool<T>& rhs) const;
        bool operator==(const safe_bool<T>& rhs) const;
};

But this still does not solve the problem of what happens if the user
provides their own conversion operator. (See Rationale section at
http://boost-consulting.com/boost/libs/utility/operators.htm#safe_bool_note
)

Since we can't select an appropiate instantiation at the derivation point.
Can we at least the warn the user if they are using an inappropiate :

safe_bool()
{
  // if this line fails to compile, consider using bool_testable
  // see documentation at http://....
  BOOST_STATIC_ASSERT(!(
    boost::is_convertible<T, char>::value ||
    boost::is_convertible<T, short>::value ||
   // ...
  ));
}

Then if the type is convertible to an integral type, then the user is told
that the implementation is inappropiate and redirected to an alternative
implementation. Similarly, bool_testable could have the corresponding
check.

Sam
******************
This e-mail has been sent from Imagination Technologies Limited.
PowerVR, Metagence, Ensigma and PURE Digital are divisions
of Imagination Technologies Limited.

The information contained in this e-mail, including any attachment,
is confidential and may be legally privileged. It is intended solely
for the addressee(s) and access to this e-mail by anyone else is
unauthorised. If you are not the intended recipient, any disclosure,
copying or distribution or use of the information contained in this
e-mail, is prohibited and may be unlawful. If you have received this
e-mail in error, please notify the sender by return e-mail and then
delete it from your system.

Internet communications cannot be guaranteed to be secure,
error or virus-free. The sender does not accept liability for any errors
or omissions which arise as a result.

Any views expressed in this message are those of the author, except
where the author specifies and, with authority, states them to be the
views of Imagination Technologies Ltd.


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