Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2005-03-05 11:12:08


David Abrahams wrote:
> "Brock Peabody" <brock.peabody_at_[hidden]> writes:
>
>
>>>On Behalf Of Fernando Cacciola
>>>Sent: Tuesday, March 01, 2005 10:39 AM
>>>To: boost_at_[hidden]
>>>Subject: [boost] Re: [optional] new assignmet semantic and references
>>
>>>So I think I will fix it unless users speak up...
>>>Though I will post this issue in the users list as well.
>>
>>First I'd like to say that I love optional<>. When I first read about it I
>>didn't think I'd use it much, but now I find myself using it all over the
>>place. It's useful for so many things, but to me the most important is how
>>it improves my ability to make code self-documenting.
>>
>>Personally, I like it the way it is. I've used optional quite a bit and it
>>makes sense to me that operator= changes what an optional holds. I don't
>>think it is a good idea to give operator= special semantics for references.
>
>
> I had the same feeling. That's what I meant when I said
>
> "It depends on whether you view optional<T> as a T that might just
> happen to be missing, or as a container for a T."
>
> I think "a container for a T" is a more manageable meaning for
> optional<T>.

FWIW, a tuple<T&> can't be re-bound.

I'll state my point again. I noticed this odd behavior of
optional some years ago: giving optional re-binding semantics
*is actually* giving it special semantics and requires special
case handling. This leads to subtle problems like the one
Fernando is experiencing now. If you want rebinding semantics,
use a pointer, or use boost::ref. The right behavior, I strongly
believe, is to do as the references do. This is what tuple did
and we have nary a problem with it.

Cheers,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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