I want know when I can memcpy an object in C++.
Thanks to this answer (When is a type in c++11 allowed to be memcpyed?) I know I can safely do this if object is TriviallyCopyable
. However, this is very strong restriction. Moreover, In my use case, I do not care, if a copy of an object made through memcpy would be the same as copy created using copy constructor.
The only thing I require is that after I memcpy an object to some memory address, I can treat this memory as original object.
Would it be enough if an object would satisfy StandardLayout
requirement or it has to be TriviallyCopyable
even in my use case?
And if StandardLayout
is not enough, what could break if I used that? It guarantess fixed object layout, right?