Boost logo

Boost :

Subject: Re: [boost] [optional] Thoughts on disallowing assignment for wrapped references.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2011-09-06 05:57:37


On Sun, 04 Sep 2011 00:33:44 -0700, Nevin Liber <nevin_at_[hidden]>
wrote:

> On 3 September 2011 21:55, Mostafa <mostafa_working_away_at_[hidden]>
> wrote:
>> Because for optional<T&>, and only for optional<T&>, the semantics of
>> the
>> assignment operator differs from the semantics of the assignment
>> operator of
>> its underlying type, namely T&. (Hence the reason for me wanting to
>> explore
>> disallowing the assignment operator for optional<T&>.)
>
> boost::optional is very consistent with respect to assignment. Given
>
> boost::optional<T> ot;
>
> 'ot = u' deals with the existence of the underlying object, while '*ot
> = v' deals with the value of the underlying object. Now, in C++,
> there is no such thing as existence without value, so you cannot
> escape dealing with the underlying value in the expression 'ot = u'.
> That holds for non-reference types as well as for references.

The Boost.Optional documentation begs to differ, direct quote:

"Rebinding semantics for the assignment of initialized optional references
has been chosen to provide consistency among initialization states even at
the expense of lack of consistency with the semantics of bare C++
references."

See: http://tinyurl.com/4yna643

Mostafa


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