Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-10-24 14:55:29


David Abrahams wrote:
> "Fernando Cacciola" <fernando_cacciola_at_[hidden]> writes:
>
>> So the only choices I see are:
>>
>> o.rebind(rb)
>>
>> or
>>
>> o = optional<T&>(rb).
>>
>> And I think I like the rebind() better.
>
> One more reason to keep the latter: don't you want to be able to put
> optional's in std::containers? I think it's important that they be
> proper values; disabling assignment altogether would be bad, and I
> don't think I want optional<T&>'s assignment operator to deep-copy the
> T.
>
Oh, I wasn't thinking at all on disabling copy assignment. That will
definitely stay.

But since you need to spell the contained type to use copy assignment I was
considering _additional_ methods that can make the assignment syntactically
easier.
A member fuction like rebind() is one alternative, but yes, there is the
problem that it makes little sense with non-rerefence types.

I suggested to add:

make_optional(v);

as a shortcut for:

optional<some_type>(v).

People argued, with reason, that you still need to discriminate yourself
references from non-references
(so you would need to use a different shortcut, like, make_optional_ref(r))

But actually I don't think having to discriminate that explicitely is much
of a probem.

So my current proposal would be:

Remove direct-assignment.
Let copy-assigment be the only way to define the wrapped value
Add make_optional() and make_optional_ref() as shorcuts to help with
copy-assignment
Keep none-assignment as the only wat to clear the wrapped value.

-- 
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/ 

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