Namespaces
Variants

std::meta::display_string_of, std::meta::u8display_string_of

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval std::string_view display_string_of( std::meta::info r );
(1) (since C++26)
consteval std::u8string_view u8display_string_of( std::meta::info r );
(2) (since C++26)

Returns an implementation-defined string. Implementations are encouraged to produce text that is helpful in identifying what r represents.

Parameters

r - a reflection value

Return value

An implementation-defined string. Where possible, the string should be suitable for identifying the represented construct.

Notes

The result V is null-terminated: V.data()[V.size()] is guaranteed to be '\0'. Each element in V is a potentially non-unique object with static storage duration that is usable in constant expressions; a pointer to such an element is not suitable for use as a template argument for a non-type template parameter of pointer type.

Example

#include <iostream>
#include <meta>
#include <vector>

struct S { int m; };
enum class E { e };
void foo() noexcept;

int main()
{
    constexpr static auto names =
    {
        std::define_static_string(display_string_of(^^S)),
        std::define_static_string(display_string_of(^^S::m)),
        std::define_static_string(display_string_of(^^E)),
        std::define_static_string(display_string_of(^^E::e)),
        std::define_static_string(display_string_of(^^foo)),
        std::define_static_string(display_string_of(^^std)),
        std::define_static_string(display_string_of(^^std::vector<int>))
    };

    for (const auto& name : names)
        std::cout << name << '\n';
}

Possible output:

S
S::m
E
E::e
void foo()
std
std::vector<int>

See also

if the reflected entity has an identifier, obtains its name
(function) [edit]