|
Boost : |
From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-09-01 12:00:12
Joel de Guzman <djowel_at_[hidden]> wrote in message
news:019401c36f79$84ccdc10$64646464_at_godzilla...
> 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);
>
>
I see the implicit value access (in foo(x)) as problematic for the reasons I gave before.
> 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;
>
Yes, I think this should be kept.
There is a special section on the documention dealing with the specific case of optional<bool>
just in order to support these _very_ idiomatic operations.
> 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!
>
The * syntax is not supposed to make optional<> pretend it is a pointer.
It is clearly not and the documentation says so quite clearly, I think.
And if it doesn't, then it is the documentation that needs to be fixed.
Fernando Cacciola
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk