Boost logo

Boost :

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


On 7 September 2011 23:15, Mostafa <mostafa_working_away_at_[hidden]> wrote:
> 1) Were the assignment operator disallowed for optional<T&> and only
> optional<T&>, there would no loss of programmatic generality when
> optional<T&> is used as a local variable.

I just don't see a use case for when it is a local variable, as it
would have the same functionality as a const pointer (with slightly
different syntax). And it would be rare indeed for me to even use
const in this case, as protecting oneself against localized coding
dicdecisions is futile, since all it takes is one edit to change it
with no repercussions outside of the function itself.

The case we've mentioned that you haven't covered is returning it from
a function, which again, is problematic for two reasons:

(1) Types that are Copyable but not Assignable are surprising
(2) It is rare to return a reference anyway, as something outside of
the callee has to manage the lifetime of the underlying object

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