Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-09-01 13:21:50


Brian McNamara <lorgon_at_[hidden]> wrote in message
news:20030831133525.A4052_at_helsinki.cc.gatech.edu...
> So I completely disagree that optionals should mix the interfaces of
> optional and the wrapped object into one. I think there should be an
> explicit unwrapping operation. But this is just my opinion, based on no
> practical evidence/experience, and I'm sure there are trade-offs either
> way. I'll explain the crux of my own reasoning below.
>
In a way you're right.
My original optional<> submision followed this rule.
safe-bool was added because of the ubiquitousness of the
implicit boolean evaluation idiom.

Implicit construction and direct assignment was left out
precisely in order to keep both interfaces separated.

> On Sun, Aug 31, 2003 at 11:59:42PM +0800, Joel de Guzman wrote:
> > It's really strange (and hard to explain) that you have to dereference
> > optional<B>. Example:
> >
> > F(tuple<A, optional<B>, C> args)
> > {
> > A a = get<1>(args);
> > B b = *get<2>(args); // strange!
> > C c = get<3>(args);
> > }
>
> I don't think it's strange at all; an optional<B> is not a B!
>
Right.
Just like any XYZ<B> is not an B, so the middle line should have
the cannonical form:

XYZ<B> b = get<2>(args).get();

Therefore, it is optional::get() that needs to be fixed, not optional::operator*(),
and not adding an implicit conversion to T.

Fernando Cacciola


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