Files
2025-10-25 03:02:53 +03:00

7.0 KiB
Raw Permalink Blame History

[meta.reflection.names]

21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.6 Reflection names and locations [meta.reflection.names]

🔗

consteval bool has_identifier(info r);

1

#

Returns:

  • (1.1)

    If r represents an entity that has a typedef name for linkage purposes ([dcl.typedef]), then true.

  • (1.2)

    Otherwise, if r represents an unnamed entity, then false.

  • (1.3)

    Otherwise, if r represents a class type, then !has_template_arguments(r).

  • (1.4)

    Otherwise, if r represents a function, then true if has_template_arguments(r) is false and the function is not a constructor, destructor, operator function, or conversion function. Otherwise, false.

  • (1.5)

    Otherwise, if r represents a template, then true if r does not represent a constructor template, operator function template, or conversion function template. Otherwise, false.

  • (1.6)

    Otherwise, if r represents the ith parameter of a function F that is an (implicit or explicit) specialization of a templated function T and the ith parameter of the instantiated declaration of T whose template arguments are those of F would be instantiated from a pack, then false.

  • (1.7)

    Otherwise, if r represents the parameter P of a function F, then let S be the set of declarations, ignoring any explicit instantiations, that precede some point in the evaluation context and that declare either F or a templated function of which F is a specialization; true if

there is a declaration D in S that introduces a name N for either P or the parameter corresponding to P in the templated function that D declares and

no declaration in S does so using any name other than N.

Otherwise, false. [Example 1: void fun(int);constexpr std::meta::info r = parameters_of(^^fun)[0];static_assert(!has_identifier(r));

void fun(int x);static_assert(has_identifier(r));

void fun(int x);static_assert(has_identifier(r));

void poison() {void fun(int y);}static_assert(!has_identifier(r)); — *end example*]
  • (1.8)

    Otherwise, if r represents a variable, then false if the declaration of that variable was instantiated from a function parameter pack. Otherwise, !has_template_arguments(r).

  • (1.9)

    Otherwise, if r represents a structured binding, then false if the declaration of that structured binding was instantiated from a structured binding pack. Otherwise, true.

  • (1.10)

    Otherwise, if r represents a type alias, then !has_template_arguments(r).

  • (1.11)

    Otherwise, if r represents an enumerator, non-static-data member, namespace, or namespace alias, then true.

  • (1.12)

    Otherwise, if r represents a direct base class relationship, then has_identifier(type_of(r)).

  • (1.13)

    Otherwise, r represents a data member description (T,N,A,W,NUA) ([class.mem.general]); true if N is not ⊥. Otherwise, false.

🔗

consteval string_view identifier_of(info r); consteval u8string_view u8identifier_of(info r);

2

#

Let E be UTF-8 for u8identifier_of, and otherwise the ordinary literal encoding.

3

#

Returns: An ntmbs, encoded with E, determined as follows:

  • (3.1)

    If r represents an entity with a typedef name for linkage purposes, then that name.

  • (3.2)

    Otherwise, if r represents a literal operator or literal operator template, then the ud-suffix of the operator or operator template.

  • (3.3)

    Otherwise, if r represents the parameter P of a function F, then let S be the set of declarations, ignoring any explicit instantiations, that precede some point in the evaluation context and that declare either F or a templated function of which F is a specialization; the name that was introduced by a declaration in S for the parameter corresponding to P.

  • (3.4)

    Otherwise, if r represents an entity, then the identifier introduced by the declaration of that entity.

  • (3.5)

    Otherwise, if r represents a direct base class relationship, then identifier_of(type_of(r)) or u8identifier_of(type_of(r)), respectively.

  • (3.6)

    Otherwise, r represents a data member description (T,N,A,W,NUA) ([class.mem.general]); a string_view or u8string_view, respectively, containing the identifier N.

4

#

Throws: meta::exception unlesshas_identifier(r) is true and the identifier that would be returned (see above) is representable by E.

🔗

consteval string_view display_string_of(info r); consteval u8string_view u8display_string_of(info r);

5

#

Returns: Animplementation-definedstring_view or u8string_view, respectively.

6

#

Recommended practice: Where possible, implementations should return a string suitable for identifying the represented construct.

🔗

consteval source_location source_location_of(info r);

7

#

Returns: If r represents a value, a type other than a class type or an enumeration type, the global namespace, or a data member description, then source_location{}.

Otherwise, animplementation-definedsource_location value.

8

#

Recommended practice: If r represents an entity with a definition that is reachable from the evaluation context, a value corresponding to a definition should be returned.