Skip to content

Commit 4e95bb5

Browse files
committed
P3096R12 Function Parameter Reflection in Reflection for C++26
1 parent 178a7f4 commit 4e95bb5

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;
@@ -3112,6 +3120,42 @@
31123120
operator function template,
31133121
or conversion function template.
31143122
Otherwise, \tcode{false}.
3123+
\item
3124+
Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter
3125+
of a function $F$,
3126+
then let $S$ be the set of declarations,
3127+
ignoring any explicit instantiations,
3128+
that precede some point in the evaluation context
3129+
and that declare either $F$ or a templated function
3130+
of which $F$ is a specialization;
3131+
\tcode{true} if
3132+
\begin{itemize}
3133+
\item
3134+
there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$
3135+
or the parameter corresponding to $P$
3136+
in the templated function that $D$ declares and
3137+
\item
3138+
no declaration in $S$ does so using any name other than $N$.
3139+
\end{itemize}
3140+
Otherwise, \tcode{false}.
3141+
\begin{example}
3142+
\begin{codeblock}
3143+
void fun(int);
3144+
constexpr std::meta::info r = parameters_of(^^fun)[0];
3145+
static_assert(!has_identifier(r));
3146+
3147+
void fun(int x);
3148+
static_assert(has_identifier(r));
3149+
3150+
void fun(int x);
3151+
static_assert(has_identifier(r));
3152+
3153+
void poison() {
3154+
void fun(int y);
3155+
}
3156+
static_assert(!has_identifier(r));
3157+
\end{codeblock}
3158+
\end{example}
31153159
\item
31163160
Otherwise, if \tcode{r} represents a variable,
31173161
then \tcode{false} if the declaration of that variable
@@ -3172,6 +3216,15 @@
31723216
\item
31733217
Otherwise, if \tcode{r} represents a literal operator or literal operator template,
31743218
then the \grammarterm{ud-suffix} of the operator or operator template.
3219+
\item
3220+
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
3221+
then let $S$ be the set of declarations,
3222+
ignoring any explicit instantiations,
3223+
that precede some point in the evaluation context
3224+
and that declare either $F$
3225+
or a templated function of which $F$ is a specialization;
3226+
the name that was introduced by a declaration in $S$
3227+
for the parameter corresponding to $P$.
31753228
\item
31763229
Otherwise, if \tcode{r} represents an entity,
31773230
then the identifier introduced by the declaration of that entity.
@@ -3270,7 +3323,11 @@
32703323
\returns
32713324
\begin{itemize}
32723325
\item
3273-
If \tcode{r} represents a
3326+
If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$,
3327+
then the $i^\text{th}$ type
3328+
in the parameter-type-list of $F$\iref{dcl.fct}.
3329+
\item
3330+
Otherwise, if \tcode{r} represents a
32743331
value,
32753332
object,
32763333
variable,
@@ -3829,6 +3886,70 @@
38293886
Otherwise, \tcode{false}.
38303887
\end{itemdescr}
38313888

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

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

41914378
\pnum

0 commit comments

Comments
 (0)