MySQL 9.7.0
Source Code Documentation
Is_trivially_comparable Concept Reference

Concept requiring that objects are copyable using memcpy, and equality-testable using memcmp. More...

#include <table_with_cursor.h>

Concept definition

template<class Type>
concept Is_trivially_comparable = std::is_trivially_copyable_v<Type>
Concept requiring that objects are copyable using memcpy, and equality-testable using memcmp.
Definition: table_with_cursor.h:59

Detailed Description

Concept requiring that objects are copyable using memcpy, and equality-testable using memcmp.

"Copyable using memcpy" is implied by std::is_trivially_copyable_v<Type>.

"Equality-testable using memcmp" cannot be checked in C++. Therefore, that is a semantic requirement (see https://en.cppreference.com/w/cpp/concepts ). A type that fails to be comparable using memcpy will not necessarily make the concept false; only make the program behavior undefined. This semantic requirement implies that the type has no internal padding bytes, which is for example guaranteed by:

  • arithmetic types (https://en.cppreference.com/w/cpp/types/is_arithmetic);
  • arrays of padding-free objects whose sizes are powers of two;
  • structs/classes which satisfy std::standard_layout_v, for which all data members (1) are padding-free, and (2) have sizes that are powers of two, and (3) are ordered by size, largest first.

Although the compiler cannot deduce if a class is equality-testable using memcmp, you can check it manually on a given platform, by verifying (recursively, for nested objets) that the sum of the sizes of all parts is equal the size of the object as a whole.

tparam Type The class to test.