
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
On 09/22/10 13:14, Larry Evans wrote: the variant implementation here: https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/co... The operator= here: https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/co... 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