|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-08-10 09:02:55
It seems to me that if you want a variant that can never be empty (and I'm
sympathetic to the importance of having a simpler invariant!) you need to
do something like the move-away-move-back trick Doug was suggesting. Sounds
like a job for move semantics.
IIUC, Howard's idea of move semantics either constructs or assigns a T,
leaving a valid but possibly changed T behind in the source object. POD
types, for example, are trivially-movable.
Maybe we just need to ask people to give us types which are
nothrow-movable, and to specialize some template for types they want to put
in a variant which aren't known to be nothrow-movable.
As a convenience, we could also allow people to pass trivially_movable<U>
to the variant, which would say "I know memcpy moves this type, and I don't
feel like specializing".
Thoughts?
BTW, Move construction would have to be emulated via something like
move-placement-new.
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave_at_[hidden] * http://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