I would define "trivially movable" by
Calling the move constructor (or the move assignment operator) is equivalent to memcpy the bytes to the new destination and not calling the destructor on the moved-from object.
For instance, if you know that this property holds, you can use realloc
to resize a std::vector or a memory pool.
Types failing this would typically have pointers to their contents that needs to be updated by the move constructor/assignment operator.
There is no such type traits in the standard that I can find. I am wondering whether this already has a (better) name, whether it's been discussed and whether there are some libraries making use of such a trait.
Edit 1:
From the first few comments, std::is_trivially_move_constructible
and std::is_trivially_move_assignable
are not equivalent to what I am looking for.
I believe they would give true
for types containing pointers to themselves, since reading your own member seems to fall under "trivial" operation.
Edit 2:
When properly implemented, types which point to themselves won't be trivially_move_constructible or move_assignable because the move ctor / move assignment operator are not trivial anymore. Though, we ought to be able to say that unique_ptr can be safely copied to a new location provided we don't call its destructor.
std::is_trivially_move_constructible
andstd::is_trivially_move_assignable
seem to be what you're after – Pirnstd::is_trivially_copyable()
already cover what you want? – Spielmemcpy
is that the type is trivially copyable, your example of self referencing objects are not. – Chloride