Spec-Zone.ru › C++

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

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

identifier_ofu8identifier_of
(C++26)(C++26)
if the reflected entity has an identifier, obtains its name
(function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/display_string_of

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API