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:
- is_standard_layout.
- is_trivially_copyable.
What I would like to know is the exact requirements when a type will be "bitwise copyable".
My conclusion is that a type is bitwise copyable if both of is_trivally_copyable
and is_standard_layout
traits are true:
- It is exactly what I need to bitwise copy?
- Is it overconstrained?
- Is it underconstrained?
P.S.: of course, the result of memcpy must be correct. I know I could memcpy in any situation but incorrectly.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…