sun::ast::VariadicParam

sun::ast::VariadicParam

struct · Source (opens in a new tab)

struct sun::ast::VariadicParam

The trailing value pack in a parameter list, as written at the end of the parentheses: a name, and the type annotation after its colon.

args... name "args", anything the call supplies args...: _params_of<T> the parameters T's init takes, or, when T is a lambda, the parameters that lambda takes

The annotation sits where an ordinary parameter's type sits, but it stands for a whole parameter list rather than one type, and the call's arguments are checked against it. It is not a constraint in the <T: _Numeric> sense: it does not narrow which types are allowed, it says where the pack's parameters come from.

A pack is not a type. It stands for however many arguments the call passes, so a declaration holding one is a template: it is monomorphized once per argument tuple, and the pack's elements become ordinary positional parameters named args.0, args.1, … in that specialization.

Public Functions

VariadicParam

VariadicParam()=default

public · function · Source (opens in a new tab)

sun::ast::VariadicParam::VariadicParam()=default

Creates a variadic parameter with its optional element annotation.

VariadicParam(std::string n, std::optional< TypeAnnotation > annot=std::nullopt)

public · function · Source (opens in a new tab)

sun::ast::VariadicParam::VariadicParam(std::string n, std::optional< TypeAnnotation > annot=std::nullopt)

Creates a variadic parameter with its optional element annotation.

Related: TypeAnnotation

elementName

public · function · Source (opens in a new tab)

std::string sun::ast::VariadicParam::elementName(size_t i) const

The element the pack materializes as at index i, e.g.

args.0. Codegen names the specialization's parameters this way and semantic analysis rewrites args... into references to exactly these names, so the two sides must agree here and nowhere else.

hasTypeAnnotation

public · function · Source (opens in a new tab)

bool sun::ast::VariadicParam::hasTypeAnnotation() const

Reports whether this object has type annotation.

Public Fields

name

public · variable · Source (opens in a new tab)

std::string sun::ast::VariadicParam::name

No documentation comment.

typeAnnotation

public · variable · Source (opens in a new tab)

std::optional<TypeAnnotation> sun::ast::VariadicParam::typeAnnotation

No documentation comment.

Related: TypeAnnotation