Boost logo

Boost :

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
> and
>> rebinding of optional references to use distinct syntax (rebind) so
> that
>> this is clearly signalled at the minor cost of some syntactic
> verbosity.
>
Which is exactly what optional does in the way I proposed it (with
rebinding)

 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
it.

>> This means that optional<T&> is no longer completely orthogonal to
>> optional<T> in its syntax, but as that merely reflects the real
> underlying
>> differences in semantics, this should be an advantage not a
> disadvantage.
>
> 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
> last
> time this was discussed.
>
FWIW, optional<T&> has the exact same semantics of optional<
reference_wrapper<T> >

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.

Best

-- 
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