Boost logo

Boost :

Subject: Re: [boost] [optional] Thoughts on disallowing assignment for wrapped references.
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-09-04 03:33:44


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.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

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