Namespaces
Variants

std::meta::variable_of

From cppreference.com
< cpp | meta
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:

  • r represents a parameter of a function F, and
  • the call to variable_of is 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:

42

See also