Files
2025-10-25 03:02:53 +03:00

5.7 KiB
Raw Permalink Blame History

[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; `

1

#

Returns: bytes * CHAR_BIT + bits.

🔗

consteval member_offset offset_of(info r);

2

#

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.

3

#

Returns: {V / CHAR_BIT, V % CHAR_BIT}.

4

#

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);

5

#

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]

6

#

Throws: meta::exception unless all of the following conditions are met:

  • (6.1)

    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 ⊥.

  • (6.2)

    If dealias(r) represents a type, then is_complete_type(r) is true.

🔗

consteval size_t alignment_of(info r);

7

#

Returns:

  • (7.1)

    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.

  • (7.2)

    Otherwise, if dealias(r) represents a variable or object, then the alignment requirement of the variable or object.

  • (7.3)

    Otherwise, if r represents a direct base class relationship, then alignment_of(type_of(r)).

  • (7.4)

    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.

  • (7.5)

    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).

8

#

Throws: meta::exception unless all of the following conditions are met:

  • (8.1)

    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.

  • (8.2)

    If dealias(r) represents a type, then is_complete_type(r) is true.

🔗

consteval size_t bit_size_of(info r);

9

#

Returns:

  • (9.1)

    If r represents an unnamed bit-field or a non-static data member that is a bit-field with width W, then W.

  • (9.2)

    Otherwise, if r represents a data member description (T,N,A,W,NUA) ([class.mem.general]) and W is not ⊥, then W.

  • (9.3)

    Otherwise, CHAR_BIT * size_of(r).

10

#

Throws: meta::exception unless all of the following conditions are met:

  • (10.1)

    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.

  • (10.2)

    If dealias(r) represents a type T, there is a point within the evaluation context from which T is not incomplete.