Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-09-14 07:16:23


From: "Fernando Cacciola" <fcacciola_at_[hidden]>
[...]
> I also made up my mind about how to let the user test if a given optional
is
> initialized or not.
> Previously, optional<> used operator void*() to allow expressions of the
> form:
>
> if ( opt ) or if ( opt != NULL )
>
> After *a lot* of consideration, I decided to support only the 'bang-bang'
> idiom:
>
> if ( !!opt ) means initialized.
> if ( !opt) means uninitialized.

I apologize if this has already been discussed, but did you consider the
idiom (often used with dynamic_cast)

optional<T> opt;

if(T * pt = opt.get())
{
// initialized, use pt
}
else
{
// not initialized, no pt in scope
}

--
Peter Dimov
Multi Media Ltd.

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