Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-11-24 09:04:01


On Monday 24 November 2003 01:55 am, Daryle Walker wrote:
> Sorry if we discussed this before, but why wouldn't:
>
> struct no_integers_except_bool
> {
> private:
> // None of these are defined
> operator signed char() const;
> operator unsigned char() const;
> operator signed short() const;
> operator unsigned short() const;
> operator int() const;
> operator unsigned() const;
> operator signed long() const;
> operator unsigned long() const;
>
> #ifdef BOOST_HAS_LONG_LONG
> operator signed long long() const;
> operator unsigned long long() const;
> #endif
>
> operator char() const;
> operator wchar_t() const;
> };
>
> block the bad effects of having an "operator bool() const"?

The problem is that is_convertible<no_integers_except_bool, int>::value
results in a compile-time error instead of being false. This is why I don't
believe bool_testable should have gone into the operators library, because it
looks like it's safe and useful but can cause annoying problems.
But alas, we don't review changes to libraries after they're accepted.

        Doug


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