Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-09-22 14:41:06


On 09/22/10 13:14, Larry Evans wrote:
> On 09/22/10 13:00, Frank Mori Hess wrote:
[snip]
>> How about if you re-assign a variant to a different type. Won't it re-use the
>> same in-place storage for a different type?
>>
> Yes, AFAICT. Thanks.
Rethought that answer because I don't (yet)
see where pointers to the 2 different types
exist at the same time in the operator= for
the variant implementation here:

https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp

The operator= here:

https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp#L314

first calls the DTOR for the lhs by calling destroy() and
only within destroy is the pointer to the lhs used.
After that, the value of the rhs is constructed in the
memory of the lhs via the assign_copy(from). A cursory
look at the assign_copy implementation doesn't show anything
used except the buffer for the lhs, which makes sense becasue
all that's required is just a call to the placement new for
using the buffer for the lhs and the value from the rhs.

I would imagine boost::variant would do something similar,
but maybe Mathias knows differently.

Mathias?

-Larry


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