21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

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

consteval bool has_identifier(info r);
Returns:
  • If r represents an entity that has a typedef name for linkage purposes ([dcl.typedef]), then true.
  • Otherwise, if r represents an unnamed entity, then false.
  • Otherwise, if r represents a class type, then !has_template_arguments(r).
  • 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.
  • 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.
  • Otherwise, if r represents the parameter of a function F that is an (implicit or explicit) specialization of a templated function T and the parameter of the instantiated declaration of T whose template arguments are those of F would be instantiated from a pack, then false.
  • 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]
  • 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).
  • 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.
  • Otherwise, if r represents a type alias, then !has_template_arguments(s).
  • Otherwise, if r represents an enumerator, non-static-data member, namespace, or namespace alias, then true.
  • Otherwise, if r represents a direct base class relationship, then has_identifier(type_of(r)).
  • Otherwise, r represents a data member description ([class.mem.general]); true if N is not ⊥.
    Otherwise, false.
consteval string_view identifier_of(info r); consteval u8string_view u8identifier_of(info r);
Let E be UTF-8 for u8identifier_of, and otherwise the ordinary literal encoding.
Constant When: has_identifier(r) is true and the identifier that would be returned (see below) is representable by E.
Returns: An ntmbs, encoded with E, determined as follows:
  • If r represents an entity with a typedef name for linkage purposes, then that name.
  • Otherwise, if r represents a literal operator or literal operator template, then the ud-suffix of the operator or operator template.
  • 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.
  • Otherwise, if r represents an entity, then the identifier introduced by the declaration of that entity.
  • Otherwise, if r represents a direct base class relationship, then identifier_of(type_of(r)) or u8identifier_of(type_of(r)), respectively.
  • Otherwise, r represents a data member description ([class.mem.general]); a string_view or u8string_view, respectively, containing the identifier N.
consteval string_view display_string_of(info r); consteval u8string_view u8display_string_of(info r);
Returns: An implementation-defined string_view or u8string_view, respectively.
Recommended practice: Where possible, implementations should return a string suitable for identifying the represented construct.
consteval source_location source_location_of(info r);
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, an implementation-defined source_location value.
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.