[meta.reflection.annotation] # 21 Metaprogramming library [[meta]](./#meta) ## 21.4 Reflection [[meta.reflection]](meta.reflection#annotation) ### 21.4.18 Annotation reflection [meta.reflection.annotation] [🔗](#lib:annotations_of) `consteval vector annotations_of(info item); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L6930) Let E be - [(1.1)](#1.1) the corresponding [*base-specifier*](class.derived.general#nt:base-specifier "11.7.1 General [class.derived.general]") if item represents a direct base class relationship, - [(1.2)](#1.2) otherwise, the entity represented by item[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L6940) *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]](expr.const "7.7 Constant expressions")) or a point immediately following the [*class-specifier*](class.pre#nt:class-specifier "11.1 Preamble [class.pre]") of the outermost class for which such a point is in a complete-class context[.](#2.sentence-1) 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[.](#2.sentence-2) 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[.](#2.sentence-3) [*Note [1](#note-1)*: The order in which two annotations appear is otherwise unspecified[.](#2.sentence-4) — *end note*] [*Example [1](#example-1)*: [[=1]] void f();[[=2, =3]] void g();void g [[=4]] (); 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; }; struct C {[[=Option{true}]] int a; [[=Option{false}]] int b;}; static_assert(extract