Subject: Re: [boost] [optional] Thoughts on disallowing assignment for wrapped references.
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-09-04 03:56:50
On 4 September 2011 00:14, Mostafa <mostafa_working_away_at_[hidden]> wrote:
> That seems to be the consensus so far. Assuming that I'm creating
> optional2, so we don't have to worry about existing code, and that it's
> equivalent to optional in all respects except that the assignment operator
> has now been disallowed across the board, and we've only retained a
> no-argument reset method. What are the implications of that?
The same problem that references and const variables have; namely, any
class that has them as members is non-Assignable (both
non-CopyAssignable and non-MoveAssignable).
It's the reason I never have const member variables, and either use
pointers, boost::optional or boost::reference_wrapper instead of C++
references as members. Not being useful as member variables is a
severe limitation. And while I do occasionally have classes that are
not Copyable, I can't think of any of those that I don't want to make
Moveable in the near future.
It isn't that vector<optional2<T>> doesn't work; it's that
vector<anytypethathasoptional2asamember> doesn't work. This is a
non-starter for many people.
That leaves using your class for local variables or parameters, and I
don't see much usefulness there either, as a pointer is a far easier
construct to use for such a localized effect.
Classes that are CopyConstructible or MoveConstructible but not
Assignable are very rare and unexpected.
-- 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