Skip to content

templates

def Bindings : Type

What the parameters are bound to (a parameter’s name, its argument).

def ClassTemplates : Type

The class templates of a program: each one’s name, parameters and definition.

def Templates.classes (items : List Item) : ClassTemplates

The class templates of the items: name, parameters and definition.

def Templates.parameterName (p : TemplateParam) : String

A template parameter’s name.

def Templates.parameterDefault (p : TemplateParam) : Option TypeSyntax

A template parameter’s default argument, if it has one.

def TemplateDefinition : Type

A function template: its parameters and its definition.

def FunctionTemplate : Type

A function template by its name.

def Templates.functions (items : List Item) : List (String * (List TemplateParam * FunctionDefinition))

The function templates of the items: name, parameters and definition.

def Templates.valueOf (b : List (String * TypeSyntax)) (x : String) : Option Int

The value a parameter is bound to, as an integer, when it is one (a non-type parameter’s argument).

def Templates.collapsed (t : TypeSyntax) : TypeSyntax

A reference to a reference collapsed ([dcl.ref]p6): an lvalue reference if either is one, else an rvalue reference; any other type as it is.

def Templates.substitution (b : List (String * TypeSyntax)) : SyntaxMap

Putting the template’s arguments in place of its parameters: a type parameter by its type (a reference to a reference so made collapsed), a non-type parameter’s uses and the array lengths written with it by its value.

def Templates.namingDepth : Nat

How many instances deep the defaults of a class template’s arguments are compared when its name is written (the types programs write are far shallower).

def Templates.spelled (ct : ClassTemplates) (t : TypeSyntax) : String

A template argument t as clang writes it (the class templates ct give the defaults to leave out).

def Templates.spelledAll (ct : ClassTemplates) (ts : List TypeSyntax) : String

Template arguments ts as clang writes them, separated by commas (the class templates ct give the defaults to leave out).

def Templates.instanceName (ct : ClassTemplates) (x : String) (args : List TypeSyntax) : String

An instance’s name: the template x’s with its arguments args (mx<int>, Box<int, 3>), a class template’s without the arguments at the end that are the defaults (std::set<int>, not std::set<int, std::less<int>>), as clang writes it; ct gives the class templates. The name is the instance’s identity: the same arguments, written or defaulted, name the same class.

def Templates.bindings(ps : List TemplateParam) (args : List TypeSyntax) : List (String * TypeSyntax)

The parameters bound to the arguments, in order.

def Templates.packOf (ps : List TemplateParam) : Option String

The type parameter pack a template ends with, if it has one.

def Templates.element (x : DeclId) (i : Nat) : DeclId

A function parameter pack’s element (args#i), a declaration of the instance.

def Templates.numberedFrom (i : Nat) (ts : List TypeSyntax) : List (Nat * TypeSyntax)

The element types of a pack with their positions.

def Templates.elementOf (x : DeclId) (pk : String) (e : Nat * TypeSyntax) : SyntaxMap

A pack expansion’s pattern for one element: the function parameter pack’s uses its element, the type parameter pack its type.

def Templates.expansion (x : DeclId) (pk : String) (elements : List TypeSyntax) : SyntaxMap

Expanding a function parameter pack x (of the type pack pk) for its element types: each pattern expansion in a call’s arguments one argument per element ([temp.variadic]p8), sizeof...(x) the number of elements.

def Templates.expandedParameters (pk : String) (elements : List TypeSyntax) (params : List Param) : List Param

The parameters with a function parameter pack (P... args) as one parameter per element, args#i.

def Templates.packParameter (params : List Param) : Option DeclId

The function parameter pack of the parameters, if there is one.

def Templates.instanceOf (ct : ClassTemplates) (ps : List TemplateParam) (f : FunctionDefinition) (args : List TypeSyntax) : Item

The instance for the arguments args of a function template (parameters ps, definition f): an ordinary function named for them (the class templates ct give the defaults its name leaves out). A variadic one’s last arguments are its pack’s elements: its function parameter pack and the expansions of it are expanded for them.

def Templates.instanceNamed (ct : ClassTemplates) (base : String) (ps : List TemplateParam) (f : FunctionDefinition) (args : List TypeSyntax) : Item

The instance for the arguments args of the template with parameters ps and definition f, named for base (the template’s name, or f#tk for one of overloads with as many template parameters, Templates.overloadBase; the class templates ct give the defaults the name leaves out).

def Templates.integerSyntax (t : IntegerType) : TypeSyntax

An integer type as written.

def Templates.named (name : String) : TypeSyntax

A class’s type by its name.

def Templates.unqualified (t : TypeSyntax) : TypeSyntax

A type without its top-level const.

def Templates.argumentName (y : String) (k : Nat) : String

The k-th template argument of a class instance, from the hidden typedef the instance comes with.

def Templates.argumentsOf (g : Globals Cpp.constructs) (y : String) (count : Nat) : Option (List TypeSyntax)

A class instance’s template arguments (count of them), from its hidden typedefs.

def Templates.lvalueTypeOf (p : Platform) (a : TypedExpr Cpp.constructs) : Ty Cpp.constructs

An argument’s type as an lvalue, without its top-level const.

def Templates.valueTypeOf (p : Platform) (a : TypedExpr Cpp.constructs) : Ty Cpp.constructs

An argument’s type as a value (an array or function decayed), without its top-level const.

def Templates.fromArgument (g : Globals Cpp.constructs) (fixed : List String) (b : Option Bindings) (p : Param) (a : TypedExpr Cpp.constructs) : Option (List (String * TypeSyntax))

Deduces from one argument a for the parameter p (in the globals g), adding to what is bound b (the parameters in fixed were written, not deduced): a reference parameter against the lvalue’s type, another against the value’s; a forwarding reference (T && of a parameter T) takes an lvalue as U & and an rvalue as U ([temp.deduct.call]p3); an rvalue does not bind to a reference to a type that is not const.

def Templates.bare (t : TypeSyntax) : TypeSyntax

A written type without its references and top-level const (std::remove_cvref_t).

def Templates.decayed (t : TypeSyntax) : TypeSyntax

A written type decayed (std::decay_t, [meta.trans.other]): references and top-level const taken away, an array the pointer to its element.

def Templates.arithmetic (t : TypeSyntax) : Bool

Whether the written type t is an arithmetic type, cv-qualified or not (std::is_arithmetic_v, [basic.fundamental]p14: the integral and the floating-point types).

def Templates.enumeration (t : TypeSyntax) : Bool

Whether the written type t is an enumeration, cv-qualified or not (std::is_enum_v, [dcl.enum]).

def Templates.truth (t : TypeSyntax) : Option Bool

A constant template argument as a truth value (an integer, nonzero is true), if it is one.

def Templates.fromTruth (b : Bool) : TypeSyntax

A truth value as a constant template argument.

def Templates.traitsDone (fuel : Nat) (t : TypeSyntax) : Option TypeSyntax

A substituted default template argument with the standard type traits it uses worked out ([meta]): decay_t, remove_reference_t, remove_cv_t, remove_const_t, is_same_v, is_arithmetic_v, is_enum_v, !; enable_if_t<c, T> is T (void without it) when c is true and fails when it is false (substitution failure, [temp.deduct]p8: none). Anything else as it is.

def Templates.traitsDoneAll (fuel : Nat) (ts : List TypeSyntax) : Option (List TypeSyntax)

Each argument with its traits worked out, unless one fails.

def Templates.trait (x : String) (args : List TypeSyntax) : Option TypeSyntax

A standard trait applied to worked-out arguments (Templates.traitsDone); a template that is not one as it is.

def Templates.completed (ps : List TemplateParam) (b : List (String * TypeSyntax)) : Option (List TypeSyntax)

Every parameter’s argument, in order: the bound one, else its default (which may use the ones before it), with the standard traits it uses worked out; a default whose substitution fails (std::enable_if_t of false) fails the deduction, so the template is not a candidate ([temp.deduct]p8).

def Templates.scalarSpellings : List (String * TypeSyntax)

The scalar types a template argument is spelled as (Templates.spelled), each with its spelling.

def Templates.unspelled (fuel : Nat) (text : String) : Option TypeSyntax

A template argument back from its spelling, when it is a scalar type or one with const, * or & on it (a class’s spelling does not say whether it is a class, a struct or a typedef: none).

def Templates.splitArguments (depth : Nat) (current : List Char) (cs : List Char) : List String

Text split at its top-level commas (not inside angle brackets), each part as written after the comma.

def Templates.argumentText (text : String) : String

A template argument’s text without the space Templates.spelledAll writes after a comma.

def Templates.overloads (templates : List FunctionTemplate) (f : String) : List TemplateDefinition

The function templates of a name (overloads of one name, [temp.over]).

def Templates.overloadFor (overloads : List (List TemplateParam * FunctionDefinition)) (count : Nat) : Option (List TemplateParam * FunctionDefinition)

Among the function templates of a name, the one an instance with a number of template arguments is of: the only one, or the one with as many parameters (or with a pack, which takes the rest); overloads that deduce the same number of arguments are not chosen between (Templates.chosen).

def Templates.overloadBase (f : String) (overloads : List TemplateDefinition) (k : Nat) : String

The name the k-th of the function templates overloads of the name f gives its instances: f itself, unless another of them has as many template parameters (then Templates.overloadFor cannot tell them apart, and the name is f#tk).

def Templates.overloadOf (overloads : List TemplateDefinition) (base : String) (count : Nat) : Option TemplateDefinition

The template among overloads that an instance base names: f#tk the k-th; f the one for the count of template arguments (Templates.overloadFor).

def Templates.baseName (base : String) : String

The name an instance base (f or f#tk) is of.

def Templates.comparedTypes (t : TemplateDefinition) : List TypeSyntax

A function template’s parameter types, without references and top-level const (as partial ordering compares them, [temp.deduct.partial]p5, p7).

def Templates.moreQualifiedReference (a : TypeSyntax) (b : TypeSyntax) : Bool

Whether a’s parameter is a reference to a type more cv-qualified than the one b’s parameter references (const T & against T &, [temp.deduct.partial]p9).

def Templates.writtenTypes (t : TemplateDefinition) : List TypeSyntax

A function template’s parameter types as written.

def Templates.atLeastAsSpecialized (g : Globals Cpp.constructs) (a : TemplateDefinition) (b : TemplateDefinition) : Bool

Whether the template a is at least as specialized as b (in the globals g, [temp.func.order]p3): b’s parameters are deduced from a’s parameter types, a’s own template parameters standing for unique types; where both parameters are lvalue references and b’s references a more cv-qualified type, a is not ([temp.deduct.partial]p9: f(const T &) is more specialized than f(T &)).

def Templates.instanceTypes (v : Nat * TemplateDefinition * List TypeSyntax) : List TypeSyntax

A viable template’s parameter types with its deduced arguments in place.

def Templates.lessQualifiedBinding (classes : ClassTemplates) (a : TypeSyntax) (b : TypeSyntax) : Bool

Whether binding an argument to the parameter type a is a better conversion than to b ([over.ics.rank]p3.2.6): both references to the same type (compared as written, with the class templates classes), b’s more cv-qualified (int & against const int &).

def Templates.betterBinding (classes : ClassTemplates) (c : Nat * TemplateDefinition * List TypeSyntax) (d : Nat * TemplateDefinition * List TypeSyntax) : Bool

Whether the viable template c’s instance is a better function than d‘s by its arguments’ conversions ([over.match.best]p1): a better reference binding for some argument and a worse one for none (the types compared as written, with the class templates classes).

def Templates.bestBound (classes : ClassTemplates) (viable : List (Nat * TemplateDefinition * List TypeSyntax)) : List (Nat * TemplateDefinition * List TypeSyntax)

The templates of viable no other one’s instance is better than by its arguments’ conversions (partial ordering chooses among these, [over.match.best]p2.5; the types compared as written, with the class templates classes).

def Templates.mostSpecialized (g : Globals Cpp.constructs) (viable : List (Nat * TemplateDefinition * List TypeSyntax)) : Option (Nat * TemplateDefinition * List TypeSyntax)

The most specialized of the viable templates (each with its index and deduced arguments, in the globals g): the one at least as specialized as every other and not the other way around ([temp.func.order]); none when no one is.

def Templates.madeInPlace (tables : CppTables) (it : Item) : Bool

Whether an instance’s definition can be made from the template as the program is checked: its body has no lambda (the program’s passes make a class for each) and every class template’s instance it writes is a class the program has (they are made when the program is prepared).

def Templates.staticCall (e : Expr) : Expr

A static member function’s call through its class (eStaticCall) once the class is known (a template’s instance written as its class first): the function C::f the class’s lowering declares (cpp.classes); any other as it is.

def Templates.instantiated (tables : CppTables) (name : String) : Option FunctionDefinition

A function template’s instance by its name (twice<int>): the template’s definition with the arguments in place, when the name is the template’s with scalar arguments spelled as Templates.instanceName spells them and the body can be made in place; none otherwise (the call asks for it: the program is prepared and checked again).

def Templates.packElements (g : Globals Cpp.constructs) (pk : String) (pattern : Param) (args : List (TypedExpr Cpp.constructs)) : Option (List TypeSyntax)

A pack’s element types from the arguments after the other parameters: each one deduced alone against the pattern ([temp.deduct.call]p1).

def Templates.deduceVariadic (g : Globals Cpp.constructs) (pk : String) (ps : List TemplateParam) (f : FunctionDefinition) (written : List TypeSyntax) (args : List (TypedExpr Cpp.constructs)) : Option (List TypeSyntax)

The template arguments a variadic template’s call deduces: the parameters before the pack as any template’s, then the pack’s elements from the remaining arguments.

def Templates.deduce (g : Globals Cpp.constructs) (ps : List TemplateParam) (f : FunctionDefinition) (written : List TypeSyntax) (args : List (TypedExpr Cpp.constructs)) : Option (List TypeSyntax)

The template arguments a call deduces: the written ones first, then from the arguments.

def Templates.deduceFixed (g : Globals Cpp.constructs) (ps : List TemplateParam) (f : FunctionDefinition) (written : List TypeSyntax) (args : List (TypedExpr Cpp.constructs)) : Option (List TypeSyntax)

The template arguments a call of a template without a pack deduces.

def Templates.hasOrdinary (g : Globals Cpp.constructs) (f : String) : Bool

Whether ordinary functions have the name too (one, or overloads f#k): a call without template arguments then chooses among them and the template’s instance (Overloading.withTemplate).

def Templates.chosen (checker : Checker Cpp.constructs) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (f : String) (written : List TypeSyntax) (args : List Expr) : Option (CheckResult Cpp.constructs String)

The function a call of a function template’s name calls: its instance for the deduced arguments, or that instance asked for; none deduced is what a call matching no function means (Cpp.mismatchOf).

def Templates.takes (f : FunctionDefinition) (count : Nat) : Bool

Whether a function takes a number of arguments: no fewer than its parameters without defaults, no more than its parameters; a function parameter pack takes any number, none too ([temp.variadic]p3).

def Templates.leftover (e : Expr) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))

A pack expansion or sizeof... left after instantiation: an expansion somewhere other than a call’s arguments is not supported yet; sizeof... of a name that is not a function parameter pack is not C++ ([expr.sizeof]p5). A static member function’s call through a type that is not a class known here (Templates.staticCall lowers the others) is not supported yet.

def Templates.expression (checker : Checker Cpp.constructs) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (e : Expr) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))

A call of a function template as an expression: its instance’s call.

def Templates.autoAsParameter : SyntaxMap

A declared type with auto in it, auto as the template parameter #auto (deduced as a function template’s parameter is, [dcl.type.auto.deduct]p4).

def Templates.hasAuto (t : TypeSyntax) : Bool

Whether a written type has auto in it.

def Templates.autoDeclaration (checker : Checker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (s : Stmt) : Option (CheckResult Cpp.constructs Stmt)

A declaration whose type has auto in it ([dcl.spec.auto]) made concrete: the type deduced from the initializer as a function template’s parameter of that type from its argument (auto drops references and top-level const, auto & binds the lvalue, const auto & reads it). Without an initializer there is nothing to deduce from.

def Templates.boundArray (g : Globals Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (t : TypeSyntax) (e : Expr) (a : TypedExpr Cpp.constructs) : Option (CheckResult Cpp.constructs Stmt)

The object a structured binding copies when it is an array (auto [a, b] = arr): an array of the same type, each element copy-initialized from the array’s ([dcl.struct.bind]p1; auto alone would decay it to a pointer); none for any other declaration. An array that is not a variable is not done (its elements would be evaluated again for each).

def Templates.statement (checker : Checker Cpp.constructs) (statements : StatementChecker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (s : Stmt) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

A call of a function template as a statement: its instance’s call.

def Templates.answer (seen : List Item) (tag : CppRequest) (types : List (Ty Cpp.constructs)) (written : List TypeSyntax) (items : List Item) : Option (List Item)

The answer to C++’s request: the items with the function template’s instance for the arguments added (the template found among the items as checking saw them: a namespace’s with its full name, a generated one).

def Templates.classNode (items : List Item) (x : String) : NodeId

A class template’s node, by its name.

def Templates.specializations (items : List Item) : List (String * ClassDefinition)

The full specializations of class templates (template <> class C<int>): the instance’s name and definition.

record Partial

A partial specialization of a class template: the template’s name, its parameters, the arguments it is for (a pattern in its parameters) and its definition.

def Templates.partials (items : List Item) : List Partial

The partial specializations of the items.

def Templates.same (ct : ClassTemplates) (a : TypeSyntax) (b : TypeSyntax) : Bool

Whether the template arguments a and b are the same: written the same (with the class templates ct).

def Partial.atLeastAs (ct : ClassTemplates) (a : Partial) (c : Partial) : Bool

Whether the partial specialization a is at least as specialized as c ([temp.class.order]): c’s pattern matches a’s (its parameters taken as types of their own; with the class templates ct).

def Partial.mostSpecialized (ct : ClassTemplates) (cs : List Partial) : Option Partial

The one of the candidates cs more specialized than every other, if there is one (with the class templates ct).

record Instance

An instance of a class template: the template’s name, its arguments and its definition (the arguments in place).

def Instance.name (i : Instance) : String

The instance i’s name: its class’s (Templates.instanceName).

def Templates.definitionFor (items : List Item) (x : String) (ps : List TemplateParam) (d : ClassDefinition) (args : List TypeSyntax) : CheckResult Cpp.constructs (List (String * TypeSyntax) * ClassDefinition)

What a class template’s definition is for these arguments, with its parameters bound: a full specialization, else the one most specialized partial specialization the arguments match, else the template itself; two or more matching with none most specialized is an error ([temp.class.spec.match]p2).

def Templates.classInstance (items : List Item) (x : String) (args : List TypeSyntax) : CheckResult Cpp.constructs Instance

A class template’s instance: its definition with the arguments in place, the template’s own name in it the instance ([temp.local]p1).

def Templates.filled (ct : ClassTemplates) (t : TypeSyntax) : TypeSyntax

A use’s default template arguments filled in ([temp.param]p10: C<int> of template <class T, int N = 4> is C<int, 4>; a default may use the parameters before it).

def Templates.fillArguments (ps : List TemplateParam) (args : List TypeSyntax) (b : List (String * TypeSyntax)) : List TypeSyntax

Arguments with the parameters’ defaults after them.

def Templates.usesIn (ct : ClassTemplates) (ts : List TypeSyntax) : List (String * List TypeSyntax)

The class template instances some types use (the arguments without parameters).

def Templates.instanceLimit : Nat

The most instances a program’s class templates may have.

def Templates.closure (items : List Item) (ct : ClassTemplates) (fuel : Nat) (found : List Instance) (todo : List (String * List TypeSyntax)) : CheckResult Cpp.constructs (List Instance)

The instances the uses need, and the ones those need, in the order found.

def Templates.memberType (t : TypeSyntax) : TypeSyntax

A member type of a class written by the name of its typedef (C::name, which the class’s lowering declares, cpp.classes), once the class is known (a template’s instance written as its class first).

def Templates.asClass (ct : ClassTemplates) (t : TypeSyntax) : TypeSyntax

A use’s instance written as the class it is (after the defaults are filled).

def Instance.items (i : Instance) : List Item

An instance’s items: its class and the hidden typedefs that keep its template arguments (deduction reads them).

def Templates.placed (ct : ClassTemplates) (instances : List Instance) (fuel : Nat) (emitted : List String) (items : List Item) : List Item * List String

The items with each instance placed before the first item that uses it (and what it uses before it).

def Templates.specialized (ct : ClassTemplates) (it : Item) : List Item

The item it as the program keeps it once its class templates are instantiated: a function template’s explicit specialization (template <> int f<int>(int)) as the instance it is (named with the class templates ct); a class template’s parameters alone, its definition an empty class (checking names instances by them, CppTables.classTemplates); a class template’s specializations dropped (the instances have them); any other as it is.

def Templates.prepare (p : Program) : CheckResult Cpp.constructs Program

A program with its class templates instantiated: each instance a class placed before its first use, the uses naming it; the function templates kept for checking to instantiate.