std::meta::info
From cppreference.com
| Defined in header <meta>
|
||
using info = decltype(^^::);
|
(since C++26) | |
std::meta::info is the type of reflection values. It is a distinct fundamental type. There exists a unique null reflection; every other reflection represents:
- a value of scalar type;
- an object of static storage duration;
- a variable;
- a structured binding;
- a function;
- a function parameter;
- an enumerator;
- an annotation;
- a type;
- a type alias;
- a class member;
- an unnamed bit-field;
- a class template;
- a function template;
- a variable template;
- an alias template;
- a concept;
- a namespace;
- a namespace alias;
- a direct base class relationship; or
- a data member description.
For the purpose of argument-dependent lookup, the namespace std::meta is an associated namespace of this type.
Values of type std::meta::info are equality-comparable. Note that a reflection of a type alias compares unequal to a reflection of the aliased type.
Example
Run this code
#include <meta>
#include <print>
// Obtain reflection object
constexpr std::meta::info r{^^int};
// Define a variable from reflection object “r”
constexpr typename [:r:] x{42};
static_assert(x == 42);
// std::meta::info objects are equality-comparable
static_assert(^^int == ^^int);
static_assert(^^int != ^^char);
// Reflection of type alias compares unequal to a reflection of the aliased type
using Int = int;
using INT = Int;
static_assert(^^int != ^^INT);
// Dealiasing can be used to reach to underlying type reflection
static_assert(^^int == std::meta::dealias(^^INT));
int main()
{
std::print("{}\n", std::meta::display_string_of(^^int));
std::print("{}\n", std::meta::display_string_of(dealias(^^INT))); // ADL
std::print("{}\n", std::meta::display_string_of(^^Int));
std::print("{}\n", std::meta::display_string_of(std::meta::info()));
}
Possible output:
int
int
Int {aka int}
<null reflection>