Boost logo

Boost :

Subject: [boost] [type_traits] what a about a trait that allows memcpy provided that destructors are not called?
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-04-24 08:50:57


Hi All,

I'm looking into writing a boost::malloc_allocator<T> class. This
allocator can also reallocate memory in-place via call's to realloc()
which can be a benefit for vector-implementation and all it's functions
that grow or shrink the vector.

However, it is normally only safe to call memcpy() for objects with a
trivial assignment operator. But we may also safely relocate a much
larger set of classes, e.g. boost::shared_ptr<T> or std::vector<T>.

At first I thought a trait like has_trivial_move_constructor<T> would be
enough, but that seems to rule out e.g. smart pointers.

The compiler can probably not detect this property, so what about a
trait like

   template< class T >
   struct is_reallocable;

Thoughts?

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk