Skip to content

Commit daa8981

Browse files
Eisenwavetkoeppe
authored andcommitted
P3096R12 Function Parameter Reflection in Reflection for C++26
1 parent d9bbb54 commit daa8981

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
@@ -5611,6 +5611,7 @@
56115611
\item a variable\iref{basic.pre},
56125612
\item a structured binding\iref{dcl.struct.bind},
56135613
\item a function\iref{dcl.fct},
5614+
\item a function parameter\iref{dcl.fct},
56145615
\item an enumerator\iref{dcl.enum},
56155616
\item an annotation\iref{dcl.attr.grammar},
56165617
\item a type alias\iref{dcl.typedef},

source/meta.tex

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,11 @@
26832683
consteval bool is_move_assignment(info r);
26842684
consteval bool is_destructor(info r);
26852685

2686+
consteval bool is_function_parameter(info r);
2687+
consteval bool is_explicit_object_parameter(info r);
2688+
consteval bool has_default_argument(info r);
2689+
consteval bool has_ellipsis_parameter(info r);
2690+
26862691
consteval bool is_template(info r);
26872692
consteval bool is_function_template(info r);
26882693
consteval bool is_variable_template(info r);
@@ -2715,6 +2720,9 @@
27152720
consteval bool has_template_arguments(info r);
27162721
consteval info template_of(info r);
27172722
consteval vector<info> template_arguments_of(info r);
2723+
consteval vector<info> parameters_of(info r);
2724+
consteval info variable_of(info r);
2725+
consteval info return_type_of(info r);
27182726

27192727
// \ref{meta.reflection.access.context}, access control context
27202728
struct access_context;
@@ -3238,6 +3246,42 @@
32383246
operator function template,
32393247
or conversion function template.
32403248
Otherwise, \tcode{false}.
3249+
\item
3250+
Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter
3251+
of a function $F$,
3252+
then let $S$ be the set of declarations,
3253+
ignoring any explicit instantiations,
3254+
that precede some point in the evaluation context
3255+
and that declare either $F$ or a templated function
3256+
of which $F$ is a specialization;
3257+
\tcode{true} if
3258+
\begin{itemize}
3259+
\item
3260+
there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$
3261+
or the parameter corresponding to $P$
3262+
in the templated function that $D$ declares and
3263+
\item
3264+
no declaration in $S$ does so using any name other than $N$.
3265+
\end{itemize}
3266+
Otherwise, \tcode{false}.
3267+
\begin{example}
3268+
\begin{codeblock}
3269+
void fun(int);
3270+
constexpr std::meta::info r = parameters_of(^^fun)[0];
3271+
static_assert(!has_identifier(r));
3272+
3273+
void fun(int x);
3274+
static_assert(has_identifier(r));
3275+
3276+
void fun(int x);
3277+
static_assert(has_identifier(r));
3278+
3279+
void poison() {
3280+
void fun(int y);
3281+
}
3282+
static_assert(!has_identifier(r));
3283+
\end{codeblock}
3284+
\end{example}
32413285
\item
32423286
Otherwise, if \tcode{r} represents a variable,
32433287
then \tcode{false} if the declaration of that variable
@@ -3298,6 +3342,15 @@
32983342
\item
32993343
Otherwise, if \tcode{r} represents a literal operator or literal operator template,
33003344
then the \grammarterm{ud-suffix} of the operator or operator template.
3345+
\item
3346+
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
3347+
then let $S$ be the set of declarations,
3348+
ignoring any explicit instantiations,
3349+
that precede some point in the evaluation context
3350+
and that declare either $F$
3351+
or a templated function of which $F$ is a specialization;
3352+
the name that was introduced by a declaration in $S$
3353+
for the parameter corresponding to $P$.
33013354
\item
33023355
Otherwise, if \tcode{r} represents an entity,
33033356
then the identifier introduced by the declaration of that entity.
@@ -3397,7 +3450,11 @@
33973450
\returns
33983451
\begin{itemize}
33993452
\item
3400-
If \tcode{r} represents a
3453+
If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$,
3454+
then the $i^\text{th}$ type
3455+
in the parameter-type-list of $F$\iref{dcl.fct}.
3456+
\item
3457+
Otherwise, if \tcode{r} represents a
34013458
value,
34023459
object,
34033460
variable,
@@ -3968,6 +4025,70 @@
39684025
Otherwise, \tcode{false}.
39694026
\end{itemdescr}
39704027

4028+
\indexlibraryglobal{is_function_parameter}%
4029+
\begin{itemdecl}
4030+
consteval bool is_function_parameter(info r);
4031+
\end{itemdecl}
4032+
4033+
\begin{itemdescr}
4034+
\pnum
4035+
\returns
4036+
\tcode{true} if \tcode{r} represents a function parameter.
4037+
Otherwise, \tcode{false}.
4038+
\end{itemdescr}
4039+
4040+
\indexlibraryglobal{is_explicit_object_parameter}%
4041+
\begin{itemdecl}
4042+
consteval bool is_explicit_object_parameter(info r);
4043+
\end{itemdecl}
4044+
4045+
\begin{itemdescr}
4046+
\pnum
4047+
\returns
4048+
\tcode{true} if \tcode{r} represents a function parameter
4049+
that is an explicit object parameter\iref{dcl.fct}.
4050+
Otherwise, \tcode{false}.
4051+
\end{itemdescr}
4052+
4053+
\indexlibraryglobal{has_default_argument}%
4054+
\begin{itemdecl}
4055+
consteval bool has_default_argument(info r);
4056+
\end{itemdecl}
4057+
4058+
\begin{itemdescr}
4059+
\pnum
4060+
\returns
4061+
If \tcode{r} represenst a parameter $P$ of a function $F$, then:
4062+
\begin{itemize}
4063+
\item
4064+
If $F$ is a specialization of a templated function $T$,
4065+
then \tcode{true} if there exists a declaration $D$ of $T$
4066+
that precedes some point in the evaluation context
4067+
and $D$ specifies a default argument
4068+
for the parameter of $T$ corresponding to $P$.
4069+
Otherwise, \tcode{false}.
4070+
\item
4071+
Otherwise, if there exists a declaration $D$ of $F$
4072+
that precedes some point in the evaluation context
4073+
and $D$ specifies a default argument for $P$,
4074+
then \tcode{true}.
4075+
\end{itemize}
4076+
Otherwise, \tcode{false}.
4077+
\end{itemdescr}
4078+
4079+
\indexlibraryglobal{has_ellipsis_parameter}%
4080+
\begin{itemdecl}
4081+
consteval bool has_ellipsis_parameter(info r);
4082+
\end{itemdecl}
4083+
4084+
\begin{itemdescr}
4085+
\pnum
4086+
\returns
4087+
\tcode{true} if \tcode{r} represents a function type
4088+
that has an ellipsis in its parameter-type-list\iref{dcl.fct}.
4089+
Otherwise, \tcode{false}.
4090+
\end{itemdescr}
4091+
39714092
\indexlibraryglobal{is_template}%
39724093
\begin{itemdecl}
39734094
consteval bool is_template(info r);
@@ -4325,6 +4446,72 @@
43254446
\end{example}
43264447
\end{itemdescr}
43274448

4449+
\indexlibraryglobal{parameters_of}%
4450+
\begin{itemdecl}
4451+
consteval vector<info> parameters_of(info r);
4452+
\end{itemdecl}
4453+
4454+
\begin{itemdescr}
4455+
\pnum
4456+
\constantwhen
4457+
\tcode{r} represents a function or a function type.
4458+
4459+
\pnum
4460+
\returns
4461+
\begin{itemize}
4462+
\item
4463+
If \tcode{r} represents a function $F$,
4464+
then a \tcode{vector} containing reflections of the parameters of $F$,
4465+
in the order they appear in a declaration of $F$.
4466+
\item
4467+
Otherwise, \tcode{r} represents a function type $T$;
4468+
a \tcode{vector} containing reflections of the types
4469+
in parameter-type-list\iref{dcl.fct} of $T$,
4470+
in the order they appear in the parameter-type-list.
4471+
\end{itemize}
4472+
\end{itemdescr}
4473+
4474+
\indexlibraryglobal{variable_of}%
4475+
\begin{itemdecl}
4476+
consteval info variable_of(info r);
4477+
\end{itemdecl}
4478+
4479+
\begin{itemdescr}
4480+
\pnum
4481+
\constantwhen
4482+
\begin{itemize}
4483+
\item
4484+
\tcode{r} represents a parameter of a function $F$ and
4485+
\item
4486+
there is a point $P$ in the evaluation context
4487+
for which the innermost non-block scope enclosing $P$
4488+
is the function parameter scope\iref{basic.scope.param}
4489+
associated with $F$.
4490+
\end{itemize}
4491+
4492+
\pnum
4493+
\returns
4494+
The reflection of the parameter variable corresponding to \tcode{r}.
4495+
\end{itemdescr}
4496+
4497+
\indexlibraryglobal{return_type_of}%
4498+
\begin{itemdecl}
4499+
consteval info return_type_of(info r);
4500+
\end{itemdecl}
4501+
4502+
\begin{itemdescr}
4503+
\pnum
4504+
\constantwhen
4505+
Either \tcode{r} represents a function
4506+
and \tcode{\exposid{has-type}(r)} is \tcode{true}
4507+
or \tcode{r} represents a function type.
4508+
4509+
\pnum
4510+
\returns
4511+
The reflection of the return type
4512+
of the function or function type represented by \tcode{r}.
4513+
\end{itemdescr}
4514+
43284515
\rSec2[meta.reflection.access.context]{Access control context}
43294516

43304517
\pnum

0 commit comments

Comments
 (0)