5.7 KiB
[meta.reflection.layout]
21 Metaprogramming library [meta]
21.4 Reflection [meta.reflection]
21.4.11 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);
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}.
Throws: meta::exception unlessr represents a non-static data member, unnamed bit-field, or direct base class relationship (D,B) for which either B is not a virtual base class or D is not an abstract class.
consteval size_t size_of(info r);
Returns: If r represents
a non-static data member of type T,
a data member description (T,N,A,W,NUA), 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]
Throws: meta::exception unless all of the following conditions are met:
-
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 (T,N,A,W,NUA) ([class.mem.general]) where W is not â¥.
-
If dealias(r) represents a type, then is_complete_type(r) is true.
consteval size_t alignment_of(info r);
Returns:
-
If dealias(r) represents a type T, then alignment_of(add_pointer(r)) if T is a reference type and the alignment requirement of T otherwise.
-
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 M of a class C, then the alignment of the direct member subobject corresponding to M of a complete object of type C.
-
Otherwise, r represents a data member description (T,N,A,W,NUA) ([class.mem.general]). If A is not â¥, then the value A. Otherwise, alignment_of(^^T).
Throws: meta::exception unless all of the following conditions are met:
-
dealias(r) is a reflection of a type, object, 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.
consteval size_t bit_size_of(info r);
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 (T,N,A,W,NUA) ([class.mem.general]) and W is not â¥, then W.
-
Otherwise, CHAR_BIT * size_of(r).
Throws: meta::exception unless all of the following conditions are met:
-
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.