c++ - In what cases do we need to know if a class is trivial? -
std::is_trival<t>::value
can determine if class t trivial. however, cannot think of scenario needs information.
are there examples?
some thoughts of mine:
provided class t trivial, mean t can safely copied memcpy
this:
t t1, t2; memcpy(&t1, &t2, sizeof(t));
?
if type trivial can, example, copied memcpy
. that's requirement user-defined types used arguments std::atomic
template. is, user-defined type t
, atomic<t>
allowed (and, larger types, required) implement assignment object of type t
object of type atomic<t>
memcpy
. similarly, testing equality, when needed, done memcmp
.
the reason using these c functions instead of c++ operators atomic operations not create calls user code. doing lead mysterious deadlocks innocent-looking code.
c++ class c++11 typetraits trivial
No comments:
Post a Comment