Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2005-10-18 13:27:45


Fernando Cacciola wrote:
> David Abrahams wrote:
>
>>Anthony Williams <anthony_w.geo_at_[hidden]> writes:
>>
>>
>>>How's this for a radical thought --- optional<T> should not be
>>>assignable from T. That way, it doesn't matter whether T is a
>>>reference, or not.
>>
>>There's at least some precedent for types that are "immutable except
>>for copy assignment."
>>
>>The assignment from T is really a kind of mutating operation.
>>
>
> Indeed.
> I'm leaning fast into dropping assignment form T.
> That definitely solves the reference binding issues.
>
>
>>>Instead, to change the binding, use reset(), and to assign use *.
>>
>>To make that valid for a null optional, I think operator* would have
>>to return a proxy reference... which is not an altogether bad idea,
>>IMO.
>>
>
> That would actually bring back the problem as assignment to a null reference
> would bind and then there's the question about what to do with assignment to
> a non-null reference (rebind as I proposed or not-rebind as Joel proposed)
> But if we do as both Sam Partignton and Antony Williams suggest, drop
> assignment from T altoghether, the situation looks a lot more clear, at
> least to me.

FWIW, I like the direction this is heading into. Dropping
assignment from T altogether is a wise move! I wouldn't mind
copy assignment and *explicit* construction. I wouldn't mind
reset(T) too. IMO, that interface is orthogonal; and there's
a clear precedent: shared_ptrs (which has both reset and copy
assignment).

Regards,

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