Boost logo

Boost :

From: Mikael Lind (mikkelin_at_[hidden])
Date: 2006-03-12 13:43:34


On 3/12/06, Václav Veselý <vaclav.vesely_at_[hidden]> wrote:
>
> There is a common need of getting a value from an optional with
> possibility
> to
> define a default value in case of the optional is uninitialized. I suggest
> two
> alternatives:
>
> optional<int> o;
> int i = o.get(123); // a meber function get with an additional
> parameter
> int j = from_optional(o, 123); // a free function
>
> Both alternatives can be implemented simultaneously.
>

Hello,

Is there any reason why you cannot do:

optional<int> o;
int i = o ? *o : 123;

Regards,
Mikael


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