Namespaces
Variants

std::meta::has_identifier

From cppreference.com
< cpp | meta
Defined in header <meta>
consteval bool has_identifier( std::meta::info r );
(since C++26)

Determines if what r represents has an associated identifier (including a literal suffix identifier).

Formally:

  • If r represents an entity with a typedef name for linkage purposes, returns true.
  • Otherwise, if r represents an unnamed class, enum, variable, bit-field, or namespace, returns false.
  • Otherwise, if r represents a type alias, returns !std::meta::has_template_arguments(r).
  • Otherwise, if r represents a type, returns true if:
  • r represents a cv-unqualified class type and std::meta::has_template_arguments(r) is false, or
  • r represents a cv-unqualified enumeration type.
  • Otherwise, if r represents a function, returns true if std::meta::has_template_arguments(r) is false, and the function is not a constructor, destructor, operator function, or conversion function.
  • Otherwise, if r represents a template, returns true if the template is not a constructor template, operator function template, or conversion function template.
  • Otherwise, if r represents a function parameter of a function that is instantiated from a function template, and the parameter is an element of a function parameter pack, returns false.
  • Otherwise, if r represents a function parameter P of a function F, then let S be the set of declarations, ignoring any explicit instantiations, that are reachable from a point in the evaluation context and that declare either F or a templated function of which F is a specialization; returns 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.
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));
  • Otherwise, if r represents a variable, returns false if either the variable corresponds to an element of a function parameter pack, or std::meta::has_template_arguments(r) is true, and returns true otherwise.
  • Otherwise, if r represents a structured binding, returns false if the structured binding is an element of a structured binding pack, or true otherwise.
  • Otherwise, if r represents an enumerator, non-static data member, namespace, or namespace alias, returns true.
  • Otherwise, if r represents a direct base class relationship, returns std::meta::has_identifier(std::meta::type_of(r)).
  • Otherwise, if r represents a data member description (T, N, A, W, NUA, ANN), returns true if the description's name N is not ⊥.
  • Otherwise, returns false.

Parameters

r - a reflection value

Return value

true if what r represents has an identifier, false otherwise.

Example

See also

converts a meta::operators enumerator to its symbolic name
(function) [edit]
if the reflected entity has an identifier, obtains its name
(function) [edit]
obtains a string suitable for identifying the reflected entity
(function) [edit]