Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-27 21:13:22


Douglas Paul Gregor <gregod_at_[hidden]> writes:

> On Mon, 27 Oct 2003, Eric Friedman wrote:
>> I'm confused. You're not actually surprised, are you?
>>
>> Attempting a copy back to the stack would not do much to solve the
>> problem. After all, if this copy fails, then we are still stuck with the
>> need to redirect visitiation requests to the heap backup.
>>
>> Right?
>
> Presumably, if you were able to copy lhs to the heap backup in the first
> place, copying back to the stack is probably okay. It's the copy of rhs
> that fails...

Wha?? Copying the _LHS_ to heap backup?? That can't possibly result
in the basic guarantee unless I've completely missed something. I
believe my suggestion has been misunderstood. The only way to get
this right is to use heap storage for the new rhs. In other words:

   variant<A,B> internally is conceptually a union {A,B,A*,B*};

   direct construction of a variant with A or B constructs an A or B
   in-place. Assignment from the same type assigns in-place.
   Assignment of the other type allocates the new RHS on the heap,
   destroys the LHS, and copies the pointer to the heap-allocated RHS
   copy into the union.

I don't see how any other scheme can work.

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