3.6 KiB
[meta.reflection.annotation]
21 Metaprogramming library [meta]
21.4 Reflection [meta.reflection]
21.4.18 Annotation reflection [meta.reflection.annotation]
consteval vector<info> annotations_of(info item);
Let E be
the corresponding base-specifier if item represents a direct base class relationship,
otherwise, the entity represented by item.
Returns: A vector containing all of the reflections R representing each annotation applying to each declaration of E that precedes either some point in the evaluation context ([expr.const]) or a point immediately following the class-specifier of the outermost class for which such a point is in a complete-class context.
For any two reflections R1 and R2 in the returned vector, if the annotation represented by R1 precedes the annotation represented by R2, then R1 appears before R2.
If R1 and R2 represent annotations from the same translation unit T, any element in the returned vector between R1 and R2 represents an annotation from T.
[Note 1:
The order in which two annotations appear is otherwise unspecified.
â end note]
[Example 1: void f(); void g();void g ();
static_assert(annotations_of(^^f).size() == 1);static_assert(annotations_of(^^g).size() == 3);static_assert([: constant_of(annotations_of(^^g)[0]) :] == 2);static_assert(extract(annotations_of(^^g)[1]) == 3);static_assert(extract(annotations_of(^^g)[2]) == 4);
struct Option { bool value; };
static_assert(extract(annotations_of(^^C::a)[0]).value);static_assert(!extract(annotations_of(^^C::b)[0]).value);
constexpr std::meta::info a1 = annotations_of(^^D)[0];constexpr std::meta::info a2 = annotations_of(^^D)[0];static_assert(a1 != a2);static_assert(constant_of(a1) == constant_of(a2));
int x, y;static_assert(annotations_of(^^x)[0] == annotations_of(^^y)[0]); â end example]
Throws: meta::exception unlessitem represents a type, type alias, variable, function, namespace, enumerator, direct base class relationship, or non-static data member.
consteval vector<info> annotations_of_with_type(info item, info type);
Returns: A vector containing each element e of annotations_of(item) whereremove_const(type_of(e)) == remove_const(type) is true, preserving their order.
Throws: meta::exception unless
annotations_of(item) is a constant expression and
dealias(type) represents a type that is complete from some point in the evaluation context.