From: Václav Veselý (vaclav.vesely_at_[hidden])
Date: 2006-03-11 14:19:42
Ulrich Eckhardt wrote:
> On Friday 10 March 2006 17:14, Vaclav Vesely wrote:
> > When two optionals (one initialized and other not) are swaped, then the
> > value in uninitialized optional is constructed and the other one in
> > initialized optional is destructed.
> > IMHO it's not necessary. It should be more effective to swap optional's
> > m_storages without any values constructiona and destruction.
> It could only be done if the object was moveable, i.e. depending on a
> type_trait. Looking at the Boost type_traits library, I wonder why this
> doesn't exist - many things can be sped up using memcpy when is_pod is
> but even things like vector/string/deque (list/map/set depending on
> their root node is stored by pointer) can be moved in memory without
> effects (yes, talking about typical implementations here, not guarantees).
I see now. But IMHO is_pod is not satisfactory condition for is_movable. For
example the class
X* me; // Can points to the instance
seems to be POD, but it's not movable. The best implicit implamentation is
probably the has_trivial_copy trait. For each other moveble type must be
is_movable explicitly specialized. (BTW for compiler writers: compiler
support for test a trait on all class members would be very useful for many
such traits. And existing compilers with support of has_trivial_copy and
similar traits must use this technique internally.)
I think it worth it. For example I use optional<string> frequently. If you
think that the is_movable trait is good enogh for Boost I would like write
it including test and documentation.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk