Skip to content

Commit 77171e6

Browse files
committed
P3096R12 Function Parameter Reflection in Reflection for C++26
1 parent 29d39cd commit 77171e6

File tree

2 files changed

+189
-1
lines changed

2 files changed

+189
-1
lines changed

source/basic.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5589,6 +5589,7 @@
55895589
\item a variable\iref{basic.pre},
55905590
\item a structured binding\iref{dcl.struct.bind},
55915591
\item a function\iref{dcl.fct},
5592+
\item a function parameter\iref{dcl.fct},
55925593
\item an enumerator\iref{dcl.enum},
55935594
\item a type alias\iref{dcl.typedef},
55945595
\item a type\iref{basic.types},

source/meta.tex

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,11 @@
26652665
consteval bool is_move_assignment(info r);
26662666
consteval bool is_destructor(info r);
26672667

2668+
consteval bool is_function_parameter(info r);
2669+
consteval bool is_explicit_object_parameter(info r);
2670+
consteval bool has_default_argument(info r);
2671+
consteval bool has_ellipsis_parameter(info r);
2672+
26682673
consteval bool is_template(info r);
26692674
consteval bool is_function_template(info r);
26702675
consteval bool is_variable_template(info r);
@@ -2697,6 +2702,9 @@
26972702
consteval bool has_template_arguments(info r);
26982703
consteval info template_of(info r);
26992704
consteval vector<info> template_arguments_of(info r);
2705+
consteval vector<info> parameters_of(info r);
2706+
consteval info variable_of(info r);
2707+
consteval info return_type_of(info r);
27002708

27012709
// \ref{meta.reflection.access.context}, access control context
27022710
struct access_context;
@@ -3111,6 +3119,42 @@
31113119
operator function template,
31123120
or conversion function template.
31133121
Otherwise, \tcode{false}.
3122+
\item
3123+
Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter
3124+
of a function $F$,
3125+
then let $S$ be the set of declarations,
3126+
ignoring any explicit instantiations,
3127+
that precede some point in the evaluation context
3128+
and that declare either $F$ or a templated function
3129+
of which $F$ is a specialization;
3130+
\tcode{true} if
3131+
\begin{itemize}
3132+
\item
3133+
there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$
3134+
or the parameter corresponding to $P$
3135+
in the templated function that $D$ declares and
3136+
\item
3137+
no declaration in $S$ does so using any name other than $N$.
3138+
\end{itemize}
3139+
Otherwise, \tcode{false}.
3140+
\begin{example}
3141+
\begin{codeblock}
3142+
void fun(int);
3143+
constexpr std::meta::info r = parameters_of(^^fun)[0];
3144+
static_assert(!has_identifier(r));
3145+
3146+
void fun(int x);
3147+
static_assert(has_identifier(r));
3148+
3149+
void fun(int x);
3150+
static_assert(has_identifier(r));
3151+
3152+
void poison() {
3153+
void fun(int y);
3154+
}
3155+
static_assert(!has_identifier(r));
3156+
\end{codeblock}
3157+
\end{example}
31143158
\item
31153159
Otherwise, if \tcode{r} represents a variable,
31163160
then \tcode{false} if the declaration of that variable
@@ -3171,6 +3215,15 @@
31713215
\item
31723216
Otherwise, if \tcode{r} represents a literal operator or literal operator template,
31733217
then the \grammarterm{ud-suffix} of the operator or operator template.
3218+
\item
3219+
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
3220+
then let $S$ be the set of declarations,
3221+
ignoring any explicit instantiations,
3222+
that precede some point in the evaluation context
3223+
and that declare either $F$
3224+
or a templated function of which $F$ is a specialization;
3225+
the name that was introduced by a declaration in $S$
3226+
for the parameter corresponding to $P$.
31743227
\item
31753228
Otherwise, if \tcode{r} represents an entity,
31763229
then the identifier introduced by the declaration of that entity.
@@ -3269,7 +3322,11 @@
32693322
\returns
32703323
\begin{itemize}
32713324
\item
3272-
If \tcode{r} represents a
3325+
If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$,
3326+
then the $i^\text{th}$ type
3327+
in the parameter-type-list of $F$\iref{dcl.fct}.
3328+
\item
3329+
Otherwise, if \tcode{r} represents a
32733330
value,
32743331
object,
32753332
variable,
@@ -3828,6 +3885,70 @@
38283885
Otherwise, \tcode{false}.
38293886
\end{itemdescr}
38303887

3888+
\indexlibraryglobal{is_function_parameter}%
3889+
\begin{itemdecl}
3890+
consteval bool is_function_parameter(info r);
3891+
\end{itemdecl}
3892+
3893+
\begin{itemdescr}
3894+
\pnum
3895+
\returns
3896+
\tcode{true} if \tcode{r} represents a function parameter.
3897+
Otherwise, \tcode{false}.
3898+
\end{itemdescr}
3899+
3900+
\indexlibraryglobal{is_explicit_object_parameter}%
3901+
\begin{itemdecl}
3902+
consteval bool is_explicit_object_parameter(info r);
3903+
\end{itemdecl}
3904+
3905+
\begin{itemdescr}
3906+
\pnum
3907+
\returns
3908+
\tcode{true} if \tcode{r} represents a function parameter
3909+
that is an explicit object parameter\iref{dcl.fct}.
3910+
Otherwise, \tcode{false}.
3911+
\end{itemdescr}
3912+
3913+
\indexlibraryglobal{has_default_argument}%
3914+
\begin{itemdecl}
3915+
consteval bool has_default_argument(info r);
3916+
\end{itemdecl}
3917+
3918+
\begin{itemdescr}
3919+
\pnum
3920+
\returns
3921+
If \tcode{r} represenst a parameter $P$ of a function $F$, then:
3922+
\begin{itemize}
3923+
\item
3924+
If $F$ is a specialization of a templated function $T$,
3925+
then \tcode{true} if there exists a declaration $D$ of $T$
3926+
that precedes some point in the evaluation context
3927+
and $D$ specifies a default argument
3928+
for the parameter of $T$ corresponding to $P$.
3929+
Otherwise, \tcode{false}.
3930+
\item
3931+
Otherwise, if there exists a declaration $D$ of $F$
3932+
that precedes some point in the evaluation context
3933+
and $D$ specifies a default argument for $P$,
3934+
then \tcode{true}.
3935+
\end{itemize}
3936+
Otherwise, \tcode{false}.
3937+
\end{itemdescr}
3938+
3939+
\indexlibraryglobal{has_ellipsis_parameter}%
3940+
\begin{itemdecl}
3941+
consteval bool has_ellipsis_parameter(info r);
3942+
\end{itemdecl}
3943+
3944+
\begin{itemdescr}
3945+
\pnum
3946+
\returns
3947+
\tcode{true} if \tcode{r} represents a function type
3948+
that has an ellipsis in its parameter-type-list\iref{dcl.fct}.
3949+
Otherwise, \tcode{false}.
3950+
\end{itemdescr}
3951+
38313952
\indexlibraryglobal{is_template}%
38323953
\begin{itemdecl}
38333954
consteval bool is_template(info r);
@@ -4185,6 +4306,72 @@
41854306
\end{example}
41864307
\end{itemdescr}
41874308

4309+
\indexlibraryglobal{parameters_of}%
4310+
\begin{itemdecl}
4311+
consteval vector<info> parameters_of(info r);
4312+
\end{itemdecl}
4313+
4314+
\begin{itemdescr}
4315+
\pnum
4316+
\constantwhen
4317+
\tcode{r} represents a function or a function type.
4318+
4319+
\pnum
4320+
\returns
4321+
\begin{itemize}
4322+
\item
4323+
If \tcode{r} represents a function $F$,
4324+
then a \tcode{vector} containing reflections of the parameters of $F$,
4325+
in the order they appear in a declaration of $F$.
4326+
\item
4327+
Otherwise, \tcode{r} represents a function type $T$;
4328+
a \tcode{vector} containing reflections of the types
4329+
in parameter-type-list\iref{dcl.fct} of $T$,
4330+
in the order they appear in the parameter-type-list.
4331+
\end{itemize}
4332+
\end{itemdescr}
4333+
4334+
\indexlibraryglobal{variable_of}%
4335+
\begin{itemdecl}
4336+
consteval info variable_of(info r);
4337+
\end{itemdecl}
4338+
4339+
\begin{itemdescr}
4340+
\pnum
4341+
\constantwhen
4342+
\begin{itemize}
4343+
\item
4344+
\tcode{r} represents a parameter of a function $F$ and
4345+
\item
4346+
there is a point $P$ in the evaluation context
4347+
for which the innermost non-block scope enclosing $P$
4348+
is the function parameter scope\iref{basic.scope.param}
4349+
associated with $F$.
4350+
\end{itemize}
4351+
4352+
\pnum
4353+
\returns
4354+
The reflection of the parameter variable corresponding to \tcode{r}.
4355+
\end{itemdescr}
4356+
4357+
\indexlibraryglobal{return_type_of}%
4358+
\begin{itemdecl}
4359+
consteval info return_type_of(info r);
4360+
\end{itemdecl}
4361+
4362+
\begin{itemdescr}
4363+
\pnum
4364+
\constantwhen
4365+
Either \tcode{r} represents a function
4366+
and \tcode{\exposid{has-type}(r)} is \tcode{true}
4367+
or \tcode{r} represents a function type.
4368+
4369+
\pnum
4370+
\returns
4371+
The reflection of the return type
4372+
of the function or function type represented by \tcode{r}.
4373+
\end{itemdescr}
4374+
41884375
\rSec2[meta.reflection.access.context]{Access control context}
41894376

41904377
\pnum

0 commit comments

Comments
 (0)