From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-12-11 10:25:06
From: "Fernando Cacciola" <fernando_cacciola_at_[hidden]>
> > > Currently, you can change the value of the optional directly without
> > > performance
> > > penalty like this: *opt = new_val, so I don't see any real need for
> > reset().
> > Not correct, *opt has undefined behavior when opt is uninitialized.
> The truth is that *opt has defined behaviour even if it is uninitialized
> used as an lvalue: it can be reset to initialized.
> IOWs, *opt=x is exactly like opt.reset(x).
> This is clearly documented, clearly shown on the examples,
> but apparently, clearly wrong :-)
> (otherwise, you and William wouldn't have mistaken it)
The documentation for
proxy optional<T>::operator* ();
says that the behavior is undefined when *this is uninitialized.
The example for proxy::operator= assigns to an initialized optional:
T v0 ;
T v1 ;
*opt = v1;
assert ( *opt == v1 ) ;
If the documentation is wrong (or am I looking at the wrong version?) and
the intent of the proxy is to allow *opt = v, having '*opt' be legal for
non-const opt but illegal for a const opt probably isn't a good idea.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk