Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-08 21:00:09

E. Gladyshev wrote:

> --- David Abrahams <dave_at_[hidden]> wrote:
> [...]
>>variant<std::vector<int>, std::string> v("hello");
>>v = std::vector<int>(3);
>>First you destroy the contained string, then you try to construct the
>>vector and it throws. The invariant says you have to contain either
>>a vector or a string, but you can't get the string back; it's likely
>>to throw on construction too.
>>The only way to maintain the basic guarantee in this case, with this
>>invariant, is to construct the vector, somewhere else, before
>>destroying the string... which means on the heap or in duplicate space
>>in the variant itself.
> Could it be done on the stack and not on heap or duplicate space?
> I think that I can outline a solution about how to do it
> w/o heap or duplicate space.

Go ahead and try, but I don't think you'll be successful.


P.S. If your "solution" is based on memcpy-away/memcpy-back, then it is
problematic because 1) it relies on undefined behavior and 2) it is not

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