Generally things check trivially constructible to avoid calling constructors and putting more work on the optimiser to remove them again.
Trivial doesn't imply that all-zeroes is some kind of null / default state. It just means the type has no invariants that need to be set by a constructor. Many things that check for trivial construction don't fill the memory with anything and just leave it uninitialised, or full it with a recogniseable pattern.
View all comments
Show parent comment
1
u/TheThiefMaster C++latest fanatic (and game dev) May 05 '26
Generally things check trivially constructible to avoid calling constructors and putting more work on the optimiser to remove them again.
Trivial doesn't imply that all-zeroes is some kind of null / default state. It just means the type has no invariants that need to be set by a constructor. Many things that check for trivial construction don't fill the memory with anything and just leave it uninitialised, or full it with a recogniseable pattern.