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
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:


as a shortcut for:


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
Keep none-assignment as the only wat to clear the wrapped value.

Fernando Cacciola

Boost list run by bdawes at, gregod at, cpdaniel at, john at