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

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


Fernando Cacciola

Boost list run by bdawes at, gregod at, cpdaniel at, john at