21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.10 Reflection layout queries [meta.reflection.layout]

struct member_offset { ptrdiff_t bytes; ptrdiff_t bits; constexpr ptrdiff_t total_bits() const; auto operator<=>(const member_offset&) const = default; }; constexpr ptrdiff_t member_offset::total_bits() const;
Returns: bytes * CHAR_BIT + bits.
consteval member_offset offset_of(info r);
Constant When: r represents a non-static data member, unnamed bit-field, or direct base class relationship for which either B is not a virtual base class or D is not an abstract class.
Let V be the offset in bits from the beginning of a complete object of the type represented by parent_of(r) to the subobject associated with the entity represented by r.
Returns: {V / CHAR_BIT, V % CHAR_BIT}.
consteval size_t size_of(info r);
Constant When: dealias(r) is a reflection of a type, object, value, variable of non-reference type, non-static data member that is not a bit-field, direct base class relationship, or data member description ([class.mem.general]) where W is not ⊥.
If dealias(r) represents a type, then is_complete_type(r) is true.
Returns: If r represents
  • a non-static data member of type T,
  • a data member description , or
  • dealias(r) represents a type T,
then sizeof(T) if T is not a reference type and size_of(​add_pointer(^^T)) otherwise.
Otherwise, size_of(type_of(r)).
[Note 1: 
It is possible that while sizeof(char)== size_of(^^char) is true, that sizeof(char&)== size_of(^^char&) is false.
If b represents a direct base class relationship of an empty base class, then size_of(b) > 0 is true.
— end note]
consteval size_t alignment_of(info r);
Constant When: dealias(r) is a reflection of a type, object, value, variable of non-reference type, non-static data member that is not a bit-field, direct base class relationship, or data member description.
If dealias(r) represents a type, then is_complete_type(r) is true.
Returns:
  • If dealias(r) represents a type T, then the alignment requirement for the layout-associated type ([class.mem.general]) for a non-static data member of type T.
  • Otherwise, if dealias(r) represents a variable or object, then the alignment requirement of the variable or object.
  • Otherwise, if r represents a direct base class relationship, then alignment_of(type_of(r)).
  • Otherwise, if r represents a non-static data member, then the alignment requirement of the subobject associated with the represented entity within any object of type parent_of(r).
  • Otherwise, r represents a data member description ([class.mem.general]).
    If A is not ⊥, then the value of A.
    Otherwise, alignment_of(^^T).
consteval size_t bit_size_of(info r);
Constant When: dealias(r) is a reflection of a type, object, value, variable of non-reference type, non-static data member, unnamed bit-field, direct base class relationship, or data member description.
If dealias(r) represents a type T, there is a point within the evaluation context from which T is not incomplete.
Returns:
  • If r represents an unnamed bit-field or a non-static data member that is a bit-field with width W, then W.
  • Otherwise, if r represents a data member description ([class.mem.general]) and W is not ⊥, then W.
  • Otherwise, CHAR_BIT * size_of(r).