|
3084 | 3084 | consteval size_t alignment_of(info r); |
3085 | 3085 | consteval size_t bit_size_of(info r); |
3086 | 3086 |
|
| 3087 | + // \ref{meta.reflection.annotation}, annotation reflection |
| 3088 | + consteval vector<info> annotations_of(info item); |
| 3089 | + consteval vector<info> annotations_of_with_type(info item, info type); |
| 3090 | + |
3087 | 3091 | // \ref{meta.reflection.extract}, value extraction |
3088 | 3092 | template<class T> |
3089 | 3093 | consteval T extract(info); |
|
3283 | 3287 | consteval info variant_alternative(size_t index, info type); |
3284 | 3288 |
|
3285 | 3289 | consteval strong_ordering type_order(info type_a, info type_b); |
3286 | | - |
3287 | | - // \ref{meta.reflection.annotation}, annotation reflection |
3288 | | - consteval vector<info> annotations_of(info item); |
3289 | | - consteval vector<info> annotations_of_with_type(info item, info type); |
3290 | 3290 | } |
3291 | 3291 | \end{codeblock} |
3292 | 3292 |
|
|
5844 | 5844 | \end{itemize} |
5845 | 5845 | \end{itemdescr} |
5846 | 5846 |
|
| 5847 | +\rSec2[meta.reflection.annotation]{Annotation reflection} |
| 5848 | + |
| 5849 | +\indexlibraryglobal{annotations_of}% |
| 5850 | +\begin{itemdecl} |
| 5851 | +consteval vector<info> annotations_of(info item); |
| 5852 | +\end{itemdecl} |
| 5853 | + |
| 5854 | +\begin{itemdescr} |
| 5855 | +\pnum |
| 5856 | +Let $E$ be |
| 5857 | +\begin{itemize} |
| 5858 | +\item |
| 5859 | + the corresponding \grammarterm{base-specifier} |
| 5860 | + if \tcode{item} represents a direct base class relationship, |
| 5861 | +\item |
| 5862 | + otherwise, the entity represented by \tcode{item}. |
| 5863 | +\end{itemize} |
| 5864 | + |
| 5865 | +\pnum |
| 5866 | +\returns |
| 5867 | +A \tcode{vector} containing all of the reflections $R$ |
| 5868 | +representing each annotation applying to each declaration of $E$ that precedes either |
| 5869 | +some point in the evaluation context\iref{expr.const} or |
| 5870 | +a point immediately following the \grammarterm{class-specifier} |
| 5871 | +of the outermost class for which such a point is in a complete-class context. |
| 5872 | +For any two reflections $R_1$ and $R_2$ in the returned \tcode{vector}, |
| 5873 | +if the annotation represented by $R_1$ precedes the annotation represented by $R_2$, |
| 5874 | +then $R_1$ appears before $R_2$. |
| 5875 | +If $R_1$ and $R_2$ represent annotations from the same translation unit $T$, |
| 5876 | +any element in the returned \tcode{vector} between $R_1$ and $R_2$ |
| 5877 | +represents an annotation from $T$. |
| 5878 | +\begin{note} |
| 5879 | +The order in which two annotations appear is otherwise unspecified. |
| 5880 | +\end{note} |
| 5881 | +\begin{example} |
| 5882 | +\begin{codeblock} |
| 5883 | +[[=1]] void f(); |
| 5884 | +[[=2, =3]] void g(); |
| 5885 | +void g [[=4]] (); |
| 5886 | + |
| 5887 | +static_assert(annotations_of(^^f).size() == 1); |
| 5888 | +static_assert(annotations_of(^^g).size() == 3); |
| 5889 | +static_assert([: constant_of(annotations_of(^^g)[0]) :] == 2); |
| 5890 | +static_assert(extract<int>(annotations_of(^^g)[1]) == 3); |
| 5891 | +static_assert(extract<int>(annotations_of(^^g)[2]) == 4); |
| 5892 | + |
| 5893 | +struct Option { bool value; }; |
| 5894 | + |
| 5895 | +struct C { |
| 5896 | + [[=Option{true}]] int a; |
| 5897 | + [[=Option{false}]] int b; |
| 5898 | +}; |
| 5899 | + |
| 5900 | +static_assert(extract<Option>(annotations_of(^^C::a)[0]).value); |
| 5901 | +static_assert(!extract<Option>(annotations_of(^^C::b)[0]).value); |
| 5902 | + |
| 5903 | +template<class T> |
| 5904 | + struct [[=42]] D { }; |
| 5905 | + |
| 5906 | +constexpr std::meta::info a1 = annotations_of(^^D<int>)[0]; |
| 5907 | +constexpr std::meta::info a2 = annotations_of(^^D<char>)[0]; |
| 5908 | +static_assert(a1 != a2); |
| 5909 | +static_assert(constant_of(a1) == constant_of(a2)); |
| 5910 | + |
| 5911 | +[[=1]] int x, y; |
| 5912 | +static_assert(annotations_of(^^x)[0] == annotations_of(^^y)[0]); |
| 5913 | +\end{codeblock} |
| 5914 | +\end{example} |
| 5915 | + |
| 5916 | +\pnum |
| 5917 | +\throws |
| 5918 | +\tcode{meta::exception} unless |
| 5919 | +\tcode{item} represents a |
| 5920 | +type, |
| 5921 | +type alias, |
| 5922 | +variable, |
| 5923 | +function, |
| 5924 | +namespace, |
| 5925 | +enumerator, |
| 5926 | +direct base class relationship, or |
| 5927 | +non-static data member. |
| 5928 | +\end{itemdescr} |
| 5929 | + |
| 5930 | +\indexlibraryglobal{annotations_of_with_type}% |
| 5931 | +\begin{itemdecl} |
| 5932 | +consteval vector<info> annotations_of_with_type(info item, info type); |
| 5933 | +\end{itemdecl} |
| 5934 | + |
| 5935 | +\begin{itemdescr} |
| 5936 | +\pnum |
| 5937 | +\returns |
| 5938 | +A \tcode{vector} containing each element \tcode{e} of \tcode{annotations_of(item)} |
| 5939 | +where |
| 5940 | +\begin{codeblock} |
| 5941 | +remove_const(type_of(e)) == remove_const(type) |
| 5942 | +\end{codeblock} |
| 5943 | +is \tcode{true}, preserving their order. |
| 5944 | + |
| 5945 | +\pnum |
| 5946 | +\throws |
| 5947 | +\tcode{meta::exception} unless |
| 5948 | +\begin{itemize} |
| 5949 | +\item |
| 5950 | + \tcode{annotations_of(item)} is a constant expression and |
| 5951 | +\item |
| 5952 | + \tcode{dealias(type)} represents a type and |
| 5953 | + \tcode{is_complete_type(type)} is \tcode{true}. |
| 5954 | +\end{itemize} |
| 5955 | +\end{itemdescr} |
| 5956 | + |
5847 | 5957 | \rSec2[meta.reflection.extract]{Value extraction} |
5848 | 5958 |
|
5849 | 5959 | \pnum |
|
6932 | 7042 | represented by \tcode{dealias(t1)} and \tcode{dealias(t2)}, respectively. |
6933 | 7043 | \end{itemdescr} |
6934 | 7044 |
|
6935 | | -\rSec2[meta.reflection.annotation]{Annotation reflection} |
6936 | | - |
6937 | | -\indexlibraryglobal{annotations_of}% |
6938 | | -\begin{itemdecl} |
6939 | | -consteval vector<info> annotations_of(info item); |
6940 | | -\end{itemdecl} |
6941 | | - |
6942 | | -\begin{itemdescr} |
6943 | | -\pnum |
6944 | | -Let $E$ be |
6945 | | -\begin{itemize} |
6946 | | -\item |
6947 | | - the corresponding \grammarterm{base-specifier} |
6948 | | - if \tcode{item} represents a direct base class relationship, |
6949 | | -\item |
6950 | | - otherwise, the entity represented by \tcode{item}. |
6951 | | -\end{itemize} |
6952 | | - |
6953 | | -\pnum |
6954 | | -\returns |
6955 | | -A \tcode{vector} containing all of the reflections $R$ |
6956 | | -representing each annotation applying to each declaration of $E$ that precedes either |
6957 | | -some point in the evaluation context\iref{expr.const} or |
6958 | | -a point immediately following the \grammarterm{class-specifier} |
6959 | | -of the outermost class for which such a point is in a complete-class context. |
6960 | | -For any two reflections $R_1$ and $R_2$ in the returned \tcode{vector}, |
6961 | | -if the annotation represented by $R_1$ precedes the annotation represented by $R_2$, |
6962 | | -then $R_1$ appears before $R_2$. |
6963 | | -If $R_1$ and $R_2$ represent annotations from the same translation unit $T$, |
6964 | | -any element in the returned \tcode{vector} between $R_1$ and $R_2$ |
6965 | | -represents an annotation from $T$. |
6966 | | -\begin{note} |
6967 | | -The order in which two annotations appear is otherwise unspecified. |
6968 | | -\end{note} |
6969 | | -\begin{example} |
6970 | | -\begin{codeblock} |
6971 | | -[[=1]] void f(); |
6972 | | -[[=2, =3]] void g(); |
6973 | | -void g [[=4]] (); |
6974 | | - |
6975 | | -static_assert(annotations_of(^^f).size() == 1); |
6976 | | -static_assert(annotations_of(^^g).size() == 3); |
6977 | | -static_assert([: constant_of(annotations_of(^^g)[0]) :] == 2); |
6978 | | -static_assert(extract<int>(annotations_of(^^g)[1]) == 3); |
6979 | | -static_assert(extract<int>(annotations_of(^^g)[2]) == 4); |
6980 | | - |
6981 | | -struct Option { bool value; }; |
6982 | | - |
6983 | | -struct C { |
6984 | | - [[=Option{true}]] int a; |
6985 | | - [[=Option{false}]] int b; |
6986 | | -}; |
6987 | | - |
6988 | | -static_assert(extract<Option>(annotations_of(^^C::a)[0]).value); |
6989 | | -static_assert(!extract<Option>(annotations_of(^^C::b)[0]).value); |
6990 | | - |
6991 | | -template<class T> |
6992 | | - struct [[=42]] D { }; |
6993 | | - |
6994 | | -constexpr std::meta::info a1 = annotations_of(^^D<int>)[0]; |
6995 | | -constexpr std::meta::info a2 = annotations_of(^^D<char>)[0]; |
6996 | | -static_assert(a1 != a2); |
6997 | | -static_assert(constant_of(a1) == constant_of(a2)); |
6998 | | - |
6999 | | -[[=1]] int x, y; |
7000 | | -static_assert(annotations_of(^^x)[0] == annotations_of(^^y)[0]); |
7001 | | -\end{codeblock} |
7002 | | -\end{example} |
7003 | | - |
7004 | | -\pnum |
7005 | | -\throws |
7006 | | -\tcode{meta::exception} unless |
7007 | | -\tcode{item} represents a |
7008 | | -type, |
7009 | | -type alias, |
7010 | | -variable, |
7011 | | -function, |
7012 | | -namespace, |
7013 | | -enumerator, |
7014 | | -direct base class relationship, or |
7015 | | -non-static data member. |
7016 | | -\end{itemdescr} |
7017 | | - |
7018 | | -\indexlibraryglobal{annotations_of_with_type}% |
7019 | | -\begin{itemdecl} |
7020 | | -consteval vector<info> annotations_of_with_type(info item, info type); |
7021 | | -\end{itemdecl} |
7022 | | - |
7023 | | -\begin{itemdescr} |
7024 | | -\pnum |
7025 | | -\returns |
7026 | | -A \tcode{vector} containing each element \tcode{e} of \tcode{annotations_of(item)} |
7027 | | -where |
7028 | | -\begin{codeblock} |
7029 | | -remove_const(type_of(e)) == remove_const(type) |
7030 | | -\end{codeblock} |
7031 | | -is \tcode{true}, preserving their order. |
7032 | | - |
7033 | | -\pnum |
7034 | | -\throws |
7035 | | -\tcode{meta::exception} unless |
7036 | | -\begin{itemize} |
7037 | | -\item |
7038 | | - \tcode{annotations_of(item)} is a constant expression and |
7039 | | -\item |
7040 | | - \tcode{dealias(type)} represents a type and |
7041 | | - \tcode{is_complete_type(type)} is \tcode{true}. |
7042 | | -\end{itemize} |
7043 | | -\end{itemdescr} |
7044 | | - |
7045 | 7045 | \rSec1[ratio]{Compile-time rational arithmetic} |
7046 | 7046 |
|
7047 | 7047 | \rSec2[ratio.general]{General} |
|
0 commit comments