std::meta::variable_of - cppreference.com
From cppreference.com
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 in the function definition.
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 corresponds to 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
#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: