Boost logo

Boost :

From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-08-31 20:01:55


Brian McNamara <lorgon_at_[hidden]> wrote:
> On Sun, Aug 31, 2003 at 10:41:15AM -0700, Mat Marcus wrote:

>> also interesting, although I think that readability suffers. I'd give
>> up bool conversion and operator! to avoid the need for ~ if that would
>> reasonably solve the muddling issues. But perhaps there would be too
>> many other problems -- I haven't explored this deeply yet.
>
> Right; to clarify, I don't think the boolean conversion operator is
> "interfering" with the implicit conversion to T. Rather I think each is
> an instance of "implicit conversion", and implicit conversions just
> don't work well with templates in general, in my experience.

It does interfere with the implicit conversion to T. Consider this:

    optional<bool> o;
    if (o)
        foo(o);

If you choose implicit conversion to T (which is debatable), the
implicit conversion to (safe)bool will have to go:

    optional<bool> o;
    if (o != none)
        foo(o);

But I see now that you are against implicit conversions, in general.
Fair enough. FWIW, I never had, nor seen, any complaints about
reference_wrapper<T>, which incidentally, has an implicit conversion
to T. In fact, I find the implicit conversion very useful.

Anyway... at the very least, I wish this is possible:

    optional<bool> o;
    if (o)
        foo(o.get());

But no, here too, we should write:

    optional<bool> o;
    if (o)
        foo(*o.get());

Which goes against existing practice in boost. See reference_wrapper::get,
tuple::get, variant::get, etc.

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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