diff --git a/source/meta.tex b/source/meta.tex index 474ef233ca..8863a42e4a 100644 --- a/source/meta.tex +++ b/source/meta.tex @@ -3080,6 +3080,10 @@ consteval size_t alignment_of(info r); consteval size_t bit_size_of(info r); + // \ref{meta.reflection.annotation}, annotation queries + consteval vector annotations_of(info item); + consteval vector annotations_of_with_type(info item, info type); + // \ref{meta.reflection.extract}, value extraction template consteval T extract(info); @@ -3279,10 +3283,6 @@ consteval info variant_alternative(size_t index, info type); consteval strong_ordering type_order(info type_a, info type_b); - - // \ref{meta.reflection.annotation}, annotation reflection - consteval vector annotations_of(info item); - consteval vector annotations_of_with_type(info item, info type); } \end{codeblock} @@ -5840,6 +5840,116 @@ \end{itemize} \end{itemdescr} +\rSec2[meta.reflection.annotation]{Annotation queries} + +\indexlibraryglobal{annotations_of}% +\begin{itemdecl} +consteval vector annotations_of(info item); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let $E$ be +\begin{itemize} +\item + the corresponding \grammarterm{base-specifier} + if \tcode{item} represents a direct base class relationship, +\item + otherwise, the entity represented by \tcode{item}. +\end{itemize} + +\pnum +\returns +A \tcode{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\iref{expr.const} or +a point immediately following the \grammarterm{class-specifier} +of the outermost class for which such a point is in a complete-class context. +For any two reflections $R_1$ and $R_2$ in the returned \tcode{vector}, +if the annotation represented by $R_1$ precedes the annotation represented by $R_2$, +then $R_1$ appears before $R_2$. +If $R_1$ and $R_2$ represent annotations from the same translation unit $T$, +any element in the returned \tcode{vector} between $R_1$ and $R_2$ +represents an annotation from $T$. +\begin{note} +The order in which two annotations appear is otherwise unspecified. +\end{note} +\begin{example} +\begin{codeblock} +[[=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