Namespaces
Variants

std::meta::object_of

From cppreference.com
< cpp | meta
Defined in header <meta>
consteval std::meta::info object_of( std::meta::info r );
(since C++26)

Given a reflection of variable, returns a reflection of the object referred to by the variable.

If r represents an object, returns r.

Parameters

r - a reflection of variable or static object

Return value

A reflection of the object referred to by what r represents.

Exceptions

Throws std::meta::exception unless r represents one of the following:

  • an object with static storage duration;
  • a variable of object type with static storage duration;
  • a variable of reference type that refers to an object with static storage duration, and either:
  • the reference is usable in a constant expression, or
  • the lifetime of the reference began within the core constant expression currently under evaluation.

Example

Can be previewed on Compiler Explorer.

#include <meta>

int x;
int& y = x;

// x and y are different variables:
static_assert(^^x != ^^y);

// x and y refer to the same object:
static_assert(std::meta::object_of(^^x) == std::meta::object_of(^^y));

int main() {}

See also

returns a reflection representing an object, suitable for use as a constant template argument
(function template) [edit]