c++ - What is the difference between is_trivially_copyable and is_trivially_copy_constructible? -
when these give different answer, , when difference useful, if @ all?
the former tests trivially copyable property, in few words means type memcpy
-safe.
a trivially copyable class class that:
— has no non-trivial copy constructors (12.8),
— has no non-trivial move constructors (12.8),
— has no non-trivial copy assignment operators (13.5.3, 12.8),
— has no non-trivial move assignment operators (13.5.3, 12.8), and
— has trivial destructor (12.4).
a trivial class class has trivial default constructor (12.1) , trivially copyable.
[ note: in particular, trivially copyable or trivial class not have virtual functions or virtual base classes.—end note ]
the latter tests presence of trivial copy constructor, incidentally requirement trivially copyable property. implies copy constructor type performs bitwise copy.
a copy/move constructor class x trivial if not user-provided , if
— class x has no virtual functions (10.3) , no virtual base classes (10.1), and
— constructor selected copy/move each direct base class subobject trivial, and
— each non-static data member of x of class type (or array thereof), constructor selected copy/move member trivial;
otherwise copy/move constructor non-trivial.
it easy fabricate type provides different results these traits:
struct foo { foo(foo const&) = default; // trivial copy constructor ~foo(); // non-trivial destructor };
Comments
Post a Comment