Boost logo

Boost :

From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-08-30 23:34:13


Brian McNamara <lorgon_at_[hidden]> wrote:

> Offhand, the "pointer interface" for reading the value of an optional
> seems good to me. Being able to say
>
> optional<int> x;
> ...
> if( x ) foo( *x );
>
> seems like a natural way to "sugarize" this in C++.

IMO, this is better:

    optional<int> x;
     if (x == none)
        foo(x);

Although I don't see this as problematic:

    optional<int> x;
     if (x)
        foo(x);

Or perhaps:

    optional<int> x;
     if (!!x)
        foo(x);

We already have an implicit conversion to safe_bool and an
operator ! anyway. Keep it. There's nothing wrong with it:

    operator unspecified-bool-type() const;
    bool operator!() const;

Perhaps it's just me, but I really dislike the * syntax. Why make optional
pretend that it is a pointer when it's clearly not! Then, we go on and give
it value semantics! C'mon!

-- 
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