samedi 14 octobre 2023

Trivially Copyable types - do all elligible methods need to be trivial?

The cppreference page for the named requirement of being TriviallyCopyable, in the subsection for classes, lists the following requirement:

Trivially copyable class

A trivially copyable class is a class that

  • has at least one eligible copy constructor, move constructor, copy assignment operator, or move assignment operator,
  • each eligible copy constructor is trivial
  • each eligible move constructor is trivial
  • each eligible copy assignment operator is trivial
  • each eligible move assignment operator is trivial, and
  • has a non-deleted trivial destructor.

so, if there's a trivial copy ctor but a non-trivial, say, move assignment operator - isn't the class trivially copyable? My intuition says that if you can construct an object of the same type by trivially copying the existing object - that's trivial copyability.

Aucun commentaire:

Enregistrer un commentaire