|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-03-05 08:58:55
"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>.
> I think it odd, for instance, that given the following optionals:
>
> int a = 5, b = 6;
>
> boost::optional<int&> ra = a, rb = b;
>
> this:
>
> ra = rb;
>
> would have different behavior than:
>
> ra.reset();
>
> ra = rb;
>
> I can understand the desire to mimic the semantics of built in C++
> references in boost::optional, but one uses boost::optional precisely in
> cases where one does not want those semantics - in cases where a reference
> may not be present, and where you may want to change which object is
> referred too.
This is what I'd have said if I'd had the time to really consider it
deeply and write it out. Nice, Brock.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk