|
Boost : |
From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-27 22:23:23
--- David Abrahams <dave_at_[hidden]> wrote:
[..]
>
> Wha?? Copying the _LHS_ to heap backup?? That can't possibly result
> in the basic guarantee unless I've completely missed something.
Yeah, we all missed something. :)
The current variant does create a heap copy of the *lhs* and
switches to it if there is an exception.
> 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.
> This was exactly my understanding
There should be a special case if the variant has a non-throw
copy-constructable type. Other than that this was my
understanding too, till I looked at the variant's codes.
If the variant doesn't have any guarantees about
the storage location of the controlled object,
it seems that it is possible to create a heap
copy of the *lhs* not *rhs* and try to allocate
*rhs* in-place. If it is true, it seems that
the current implementation is more efficient
in terms of memory fragmentation (create a temp. *lhs*
and if everything is fine, delete it). For example
provided that there were no exceptions,
an array of variants will occupy a continuous
chunk of storage.
Also, I mentioned it to Eric that the current
implementation doesn't actually provide basic guarantees.
He was going to look into that.
Eugene
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk