Subject: Re: [boost] [optional] Thoughts on disallowing assignment for wrapped references.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2011-09-13 23:15:34
On Tue, 30 Aug 2011 22:23:58 -0700, Mostafa
> Boost.Optional seems to really have a lot of potential for what I want
> to do, but one thing about it has been nagging me, specifically it's
> assignment semantics for wrapped references being different from the
> semantics of bare C++ references (see http://tinyurl.com/4yna643).
> Has/have the author(s) of the library or anyone considered disallowing
> assignment for Boost.Optional types that wrap references, and if so,
> what would the consequences of this entail? I rather disallow
> assignment in this case, then have what's basically a wrapper class
> behave partially differently than the type it's supposed to emulate.
As promised, attached is a matrix of alternatives to operator= with
accompanying pros/cons and supplementary reference to explain in detail
what may not be obvious. This matrix and it's examples were culled from
the archives and this thread. Are there any alternatives that were
discussed but which I omitted from the matrix?
Hi Fernando (anybody else that may care to jump in),
In this posting: http://tinyurl.com/6k37wrc, you noted that optional<T&>
can be replaced by optional<reference_wrapper<T> >, and asked why
optional<T&> would still be needed. Gennadiy Rozental responded that it
is still needed for generic programming, else he would have to support a
special case. Can you enlighten me how this is so, so I can add the
rational to the cons section of alt4_optional in the attached doc. (I
would think that judicious use of boost::ref/cref would obviate the need
for any special cases in generic programming.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk