When is a type in c++11 allowed to be memcpyed?

后端 未结 5 514
滥情空心
滥情空心 2020-11-30 05:48

My question is the following:

If I want to copy a class type, memcpy can do it very fast. This is allowed in some situations.

We have some type traits:

5条回答
  •  温柔的废话
    2020-11-30 06:26

    What I understood is

    • An Object should have default constructor /destructor.
    • Default Copy and Move Operations.
    • No static and Virtual Functions has multiple
    • access specifiers for non-static data members prevents important
    • layout optimizations has a non-static member or a base that is not standard layout.

    you can test if given type is pod (Plain Old Data) by using standard function is_pod::value

    Reference: The C++ programming Language 4th edition

提交回复
热议问题