From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-10-17 15:48:37
Brock Peabody wrote:
>> On Behalf Of Leo Goodstadt
>> The easiest solution to disambiguate, would be to force all binding
>> rebinding of optional references to use distinct syntax (rebind) so
>> this is clearly signalled at the minor cost of some syntactic
Which is exactly what optional does in the way I proposed it (with
opt = value ; // always rebinds
*opt = *value ; // never rebinds (but is UB if *opt refers to nothing)
Notice that the code I posted and where you saw yourself the problem shows
the behaviour that would existed if optional<> were not the way I designed
>> This means that optional<T&> is no longer completely orthogonal to
>> optional<T> in its syntax, but as that merely reflects the real
>> differences in semantics, this should be an advantage not a
> An easy way to do that would be to disallow optional<T&> and spell it
> instead as optional<reference_wrapper<T> > as someone suggested the
> time this was discussed.
FWIW, optional<T&> has the exact same semantics of optional<
rebinding on assignment included.
NOTE: Don't get distracted by the fact that reference_wrapper<T> istself
doesn't rebind on assigment.
If _that_ is stored as the value of an optional<>, then _direct_ assignment
(opt=val) would always rebind and _indirect_ asssignment (*o=val), would
never rebind; just as it is now with my proposed rebinding.
-- Fernando Cacciola SciSoft http://fcacciola.50webs.com/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk