Skip to main content
Log in

Mojo struct

VariadicPack

A utility class to access variadic pack arguments and provide an API for doing things with them.

Parameters

  • elt_is_mutable (i1): True if the elements of the list are mutable for an inout or owned argument pack.
  • lifetime (AnyLifetime[elt_is_mutable]): The reference lifetime of the underlying elements.
  • element_trait (AnyTrait[AnyType]): The trait that each element of the pack conforms to.
  • *element_types (element_trait): The list of types held by the argument pack.

Implemented traits

AnyType, Sized

Methods

__init__

__init__(inout self: Self, value: !lit.ref.pack<:variadic<!kgen.paramref<:!lit.anytrait<<_stdlib::_builtin::_anytype::_AnyType>> element_trait>> element_types, mut=elt_is_mutable, lifetime>, is_owned: Bool)

Constructs a VariadicPack from the internal representation.

Args:

  • value (!lit.ref.pack<:variadic<!kgen.paramref<:!lit.anytrait<<_stdlib::_builtin::_anytype::_AnyType>> element_trait>> element_types, mut=elt_is_mutable, lifetime>): The argument to construct the pack with.
  • is_owned (Bool): Whether this is an 'owned' pack or 'inout'/'borrowed'.

__del__

__del__(owned self: Self)

Destructor that releases elements if owned.

__getitem__

__getitem__[index: Int](self: Self) -> ref [lifetime] element_types[$0.value]

Return a reference to an element of the pack.

Parameters:

  • index (Int): The element of the pack to return.

Returns:

A reference to the element. The Reference's mutability follows the mutability of the pack argument convention.

__len__

static __len__() -> Int

Return the VariadicPack length.

Returns:

The number of elements in the variadic pack.

__len__(self: Self) -> Int

Return the VariadicPack length.

Returns:

The number of elements in the variadic pack.

each

each[func: fn[element_trait]($0) capturing -> None](self: Self)

Apply a function to each element of the pack in order. This applies the specified function (which must be parametric on the element type) to each element of the pack, from the first element to the last, passing in each element as a borrowed argument.

Parameters:

  • func (fn[element_trait]($0) capturing -> None): The function to apply to each element.

each_idx

each_idx[func: fn[Int, element_trait]($1) capturing -> None](self: Self)

Apply a function to each element of the pack in order. This applies the specified function (which must be parametric on the element type) to each element of the pack, from the first element to the last, passing in each element as a borrowed argument.

Parameters:

  • func (fn[Int, element_trait]($1) capturing -> None): The function to apply to each element.

Was this page helpful?