I have a class like so:
Snippet 1:
struct B
{
int member;
// more complex members e.g. arrays of structs etc
};
This class is used in the code assuming it is a C style struct (e.g. used in memcpy, memset etc)
As part of good programming principles, I am contemplating modifying B like so:
Snippet 2
struct B
{
B() {}
int member;
// more complex members e.g. arrays of structs etc
};
Here is my understanding. Please correct if I got this wrong a. Snippet 1 defines B which is a POD whereas Snippet 2 defines B which is not a POD, AND b. In Snippet 2, B can still be legitimately used for C style uses such as memset and memcpy
- std::is_pod : false
- std::is_trivial : false
- std::is_trivially_copyable : true
- std::is_trivial : false
Extending, I would also follow the rule of Big 3 (or perhaps Big 5), I would add copy assignment as well as copy constructor.
Snippet 3:
struct B
{
B() {}
~B(){}
B& operator=(B &){ return *this; }
B(B const &r){}
int member;
// more complex members e.g. arrays of structs etc
};
Here is my understanding. Please correct if I got this wrong a. In Snippet 3, B can now no longer be legitimately used for C style uses such as memset and memcpy
- std::is_pod : false
- std::is_trivial : false
- std::is_trivially_copyable : false
- std::is_trivial : false
I need understanding on the effect of adding various members to B in Snippet 2 and Snippet 3 on C style uses of B.
Is the C Style use of a class really based on is_trivially_copyable or on is_trivial (which is more restrictive)?
Reading $3.9/2 indicates to me that in C++11 "is_trivially_copyable" is really the determining criteria. Some old C++ books (C++ in a nutshell e.g.) however indicate the criteria is about POD vs non POD and I understand that C++11 rules have changed since.
Petes response seems to indicate that trivial-ness is the necessary criteria