Files
cppdraft_translate/cppdraft/meta/reflection/result.md
2025-10-25 03:02:53 +03:00

3.8 KiB
Raw Blame History

[meta.reflection.result]

21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.14 Expression result reflection [meta.reflection.result]

🔗

template<class T> consteval info reflect_constant(T expr);

1

#

Mandates: is_copy_constructible_v is true and T is a cv-unqualified structural type ([temp.param]) that is not a reference type.

2

#

Let V be:

if T is a class type, then an object that is template-argument-equivalent to the value of expr;

otherwise, the value of expr.

3

#

Returns: template_arguments_of(^^TCls)[0], with TCls as defined below.

[Note 1:

This is a reflection of an object for class types, and a reflection of a value otherwise.

— end note]

4

#

Throws: meta::exception unless the template-id TCls would be valid given the invented templatetemplate struct TCls;

5

#

[Example 1: templatestruct A { };

struct N { int x; };struct K { char const* p; };

constexpr info r1 = reflect_constant(42);static_assert(is_value(r1));static_assert(r1 == template_arguments_of(^^A<42>)[0]);

constexpr info r2 = reflect_constant(N{42});static_assert(is_object(r2));static_assert(r2 == template_arguments_of(^^A<N{42}>)[0]);

constexpr info r3 = reflect_constant(K{nullptr}); // OKconstexpr info r4 = reflect_constant(K{"ebab"}); // error: constituent pointer// points to string literal — end example]

🔗

template<class T> consteval info reflect_object(T& expr);

6

#

Mandates: T is an object type.

7

#

Returns: A reflection of the object designated by expr.

8

#

Throws: meta::exception unlessexpr is suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]).

🔗

template<class T> consteval info reflect_function(T& fn);

9

#

Mandates: T is a function type.

10

#

Returns: A reflection of the function designated by fn.

11

#

Throws: meta::exception unlessfn is suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]).