[type_traits] what a about a trait that allows memcpy provided that destructors are not called?

24 Apr
2010
24 Apr
'10
12:50 p.m.
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
5530
Age (days ago)
5530
Last active (days ago)
0 comments
1 participants
participants (1)
-
Thorsten Ottosen