std::meta::variable_of
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info variable_of( std::meta::info r );
|
(since C++26) | |
Given a reflection r that represents a function parameter, returns a reflection that represents the corresponding variable.
Parameter value
| r | - | a reflection that represents a function parameter (i.e. an element of std::meta::parameters_of(rf) where rf represents a function)
|
Return value
A reflection that represents a variable, which is the function parameter represented by r.
Exceptions
Throws std::meta::exception unless:
rrepresents a parameter of a function F, and- the call to
variable_ofis part of the evaluation of F's function body.
Example
Run this code
#include <meta>
#include <print>
void f(int int_arg) {
constexpr auto rp = std::meta::parameters_of(^^f)[0];
// const int& x = [:rp:]; // error: cannot splice the reflection of a parameter
const int& x = [:std::meta::variable_of(rp):]; // OK, x refers to int_arg
std::println("{}", x);
}
int main() {
f(42);
}
Output:
42
See also
| This section is incomplete |