Skip to content

P3096R12 Function Parameter Reflection in Reflection for C++26 #8045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5611,6 +5611,7 @@
\item a variable\iref{basic.pre},
\item a structured binding\iref{dcl.struct.bind},
\item a function\iref{dcl.fct},
\item a function parameter\iref{dcl.fct},
\item an enumerator\iref{dcl.enum},
\item an annotation\iref{dcl.attr.grammar},
\item a type alias\iref{dcl.typedef},
Expand Down
201 changes: 197 additions & 4 deletions source/meta.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,11 @@
consteval bool is_move_assignment(info r);
consteval bool is_destructor(info r);

consteval bool is_function_parameter(info r);
consteval bool is_explicit_object_parameter(info r);
consteval bool has_default_argument(info r);
consteval bool has_ellipsis_parameter(info r);

consteval bool is_template(info r);
consteval bool is_function_template(info r);
consteval bool is_variable_template(info r);
Expand Down Expand Up @@ -2715,6 +2720,9 @@
consteval bool has_template_arguments(info r);
consteval info template_of(info r);
consteval vector<info> template_arguments_of(info r);
consteval vector<info> parameters_of(info r);
consteval info variable_of(info r);
consteval info return_type_of(info r);

// \ref{meta.reflection.access.context}, access control context
struct access_context;
Expand Down Expand Up @@ -3238,6 +3246,47 @@
operator function template,
or conversion function template.
Otherwise, \tcode{false}.
\item
Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter of a function $F$
that is an (implicit or explicit) specialization of a templated function $T$
and the $i^\text{th}$ parameter of the instantiated declaration of $T$
whose template arguments are those of $F$ would be instantiated from a pack,
then \tcode{false}.
\item
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
then let $S$ be the set of declarations,
ignoring any explicit instantiations,
that precede some point in the evaluation context
and that declare either $F$ or a templated function
of which $F$ is a specialization;
\tcode{true} if
\begin{itemize}
\item
there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$
or the parameter corresponding to $P$
in the templated function that $D$ declares and
\item
no declaration in $S$ does so using any name other than $N$.
\end{itemize}
Otherwise, \tcode{false}.
\begin{example}
\begin{codeblock}
void fun(int);
constexpr std::meta::info r = parameters_of(^^fun)[0];
static_assert(!has_identifier(r));

void fun(int x);
static_assert(has_identifier(r));

void fun(int x);
static_assert(has_identifier(r));

void poison() {
void fun(int y);
}
static_assert(!has_identifier(r));
\end{codeblock}
\end{example}
\item
Otherwise, if \tcode{r} represents a variable,
then \tcode{false} if the declaration of that variable
Expand Down Expand Up @@ -3298,6 +3347,15 @@
\item
Otherwise, if \tcode{r} represents a literal operator or literal operator template,
then the \grammarterm{ud-suffix} of the operator or operator template.
\item
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
then let $S$ be the set of declarations,
ignoring any explicit instantiations,
that precede some point in the evaluation context
and that declare either $F$
or a templated function of which $F$ is a specialization;
the name that was introduced by a declaration in $S$
for the parameter corresponding to $P$.
\item
Otherwise, if \tcode{r} represents an entity,
then the identifier introduced by the declaration of that entity.
Expand Down Expand Up @@ -3378,8 +3436,9 @@
enumerator,
non-static data member,
unnamed bit-field,
direct base class relationship, or
data member description.
direct base class relationship,
data member description, or
function parameter.
Otherwise, \tcode{false}.
\end{itemdescr}

Expand All @@ -3397,7 +3456,11 @@
\returns
\begin{itemize}
\item
If \tcode{r} represents a
If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$,
then the $i^\text{th}$ type
in the parameter-type-list of $F$\iref{dcl.fct}.
\item
Otherwise, if \tcode{r} represents a
value,
object,
variable,
Expand Down Expand Up @@ -3968,6 +4031,70 @@
Otherwise, \tcode{false}.
\end{itemdescr}

\indexlibraryglobal{is_function_parameter}%
\begin{itemdecl}
consteval bool is_function_parameter(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\returns
\tcode{true} if \tcode{r} represents a function parameter.
Otherwise, \tcode{false}.
\end{itemdescr}

\indexlibraryglobal{is_explicit_object_parameter}%
\begin{itemdecl}
consteval bool is_explicit_object_parameter(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\returns
\tcode{true} if \tcode{r} represents a function parameter
that is an explicit object parameter\iref{dcl.fct}.
Otherwise, \tcode{false}.
\end{itemdescr}

\indexlibraryglobal{has_default_argument}%
\begin{itemdecl}
consteval bool has_default_argument(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\returns
If \tcode{r} represenst a parameter $P$ of a function $F$, then:
\begin{itemize}
\item
If $F$ is a specialization of a templated function $T$,
then \tcode{true} if there exists a declaration $D$ of $T$
that precedes some point in the evaluation context
and $D$ specifies a default argument
for the parameter of $T$ corresponding to $P$.
Otherwise, \tcode{false}.
\item
Otherwise, if there exists a declaration $D$ of $F$
that precedes some point in the evaluation context
and $D$ specifies a default argument for $P$,
then \tcode{true}.
\end{itemize}
Otherwise, \tcode{false}.
\end{itemdescr}

\indexlibraryglobal{has_ellipsis_parameter}%
\begin{itemdecl}
consteval bool has_ellipsis_parameter(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\returns
\tcode{true} if \tcode{r} represents a function type
that has an ellipsis in its parameter-type-list\iref{dcl.fct}.
Otherwise, \tcode{false}.
\end{itemdescr}

\indexlibraryglobal{is_template}%
\begin{itemdecl}
consteval bool is_template(info r);
Expand Down Expand Up @@ -4266,7 +4393,7 @@
A \tcode{vector} containing reflections
of the template arguments
of the template specialization represented by \tcode{r},
in the order they appear in the corresponding template argument list.
in the order in which they appear in the corresponding template argument list.
For a given template argument $A$,
its corresponding reflection $R$ is determined as follows:
\begin{itemize}
Expand Down Expand Up @@ -4325,6 +4452,72 @@
\end{example}
\end{itemdescr}

\indexlibraryglobal{parameters_of}%
\begin{itemdecl}
consteval vector<info> parameters_of(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\constantwhen
\tcode{r} represents a function or a function type.

\pnum
\returns
\begin{itemize}
\item
If \tcode{r} represents a function $F$,
then a \tcode{vector} containing reflections of the parameters of $F$,
in the order in which they appear in a declaration of $F$.
\item
Otherwise, \tcode{r} represents a function type $T$;
a \tcode{vector} containing reflections of the types
in parameter-type-list\iref{dcl.fct} of $T$,
in the order in which they appear in the parameter-type-list.
\end{itemize}
\end{itemdescr}

\indexlibraryglobal{variable_of}%
\begin{itemdecl}
consteval info variable_of(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\constantwhen
\begin{itemize}
\item
\tcode{r} represents a parameter of a function $F$ and
\item
there is a point $P$ in the evaluation context
for which the innermost non-block scope enclosing $P$
is the function parameter scope\iref{basic.scope.param}
associated with $F$.
\end{itemize}

\pnum
\returns
The reflection of the parameter variable corresponding to \tcode{r}.
\end{itemdescr}

\indexlibraryglobal{return_type_of}%
\begin{itemdecl}
consteval info return_type_of(info r);
\end{itemdecl}

\begin{itemdescr}
\pnum
\constantwhen
Either \tcode{r} represents a function
and \tcode{\exposid{has-type}(r)} is \tcode{true}
or \tcode{r} represents a function type.

\pnum
\returns
The reflection of the return type
of the function or function type represented by \tcode{r}.
\end{itemdescr}

\rSec2[meta.reflection.access.context]{Access control context}

\pnum
Expand Down