21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.8 Scope identification [meta.reflection.scope]

The functions in this subclause retrieve information about where in the program they are invoked.
None of the functions in this subclause is an addressable function ([namespace.std]).
Given a program point P, let eval-point(P) be the following program point:
  • If a potentially-evaluated subexpression ([intro.execution]) of a default member initializer I for a member of class C ([class.mem.general]) appears at P, then a point determined as follows:
    • If an aggregate initialization is using I, eval-point(Q), where Q is the point at which that aggregate initialization appears.
    • Otherwise, if an initialization by an inherited constructor ([class.inhctor.init]) is using I, a point whose immediate scope is the class scope corresponding to C.
    • Otherwise, a point whose immediate scope is the function parameter scope corresponding to the constructor definition that is using I.
  • Otherwise, if a potentially-evaluated subexpression of a default argument ([dcl.fct.default]) appears at P, eval-point(Q), where Q is the point at which the invocation of the function ([expr.call]) using that default argument appears.
  • Otherwise, if the immediate scope of P is a function parameter scope introduced by a declaration D, and P appears either before the locus of D or within the trailing requires-clause of D, a point whose immediate scope is the innermost scope enclosing the locus of D that is not a template parameter scope.
  • Otherwise, if the immediate scope of P is a function parameter scope introduced by a lambda-expression L whose lambda-introducer appears at point Q, and P appears either within the trailing-return-type or the trailing requires-clause of L, eval-point(Q).
  • Otherwise, if the innermost non-block scope enclosing P is the function parameter scope introduced by a consteval-block-declaration ([dcl.pre]), a point whose immediate scope is that inhabited by the outermost consteval-block-declaration D containing P such that each scope (if any) that intervenes between P and the function parameter scope introduced by D is either
  • Otherwise, P.
Given a scope S, let ctx-scope(S) be the following scope:
  • If S is a class scope or namespace scope, S.
  • Otherwise, if S is a function parameter scope introduced by the declaration of a function, S.
  • Otherwise, if S is a lambda scope introduced by a lambda-expression L, the function parameter scope corresponding to the call operator of the closure type of L.
  • Otherwise, ctx-scope(), where is the parent scope of S.
Let CURRENT-SCOPE(P) for a point P be a reflection representing the function, class, or namespace whose corresponding function parameter scope, class scope, or namespace scope, respectively, is ctx-scope(S), where S is the immediate scope of eval-point(P).
consteval info current_function();
An invocation of current_function that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.
Let S be CURRENT-SCOPE(P), where P is the point at which the invocation of current_function lexically appears.
Returns: S.
Throws: meta​::​exception unless S represents a function.
consteval info current_class();
An invocation of current_class that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.
Let S be CURRENT-SCOPE(P) where P is the point at which the invocation of current_class lexically appears.
Returns: S if S represents a class.
Otherwise, parent_of(S).
Throws: meta​::​exception unless S represents either a class or a member function.
consteval info current_namespace();
An invocation of current_namespace that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.
Let S be CURRENT-SCOPE(P) where P is the point at which the invocation of current_namespace lexically appears.
Returns: S if S represents a namespace.
Otherwise, a reflection representing the nearest enclosing namespace of the entity represented by S.