Skip to main content
Log in

Mojo struct

VariadicPack

@register_passable struct VariadicPack[elt_is_mutable: Bool, //, origin: Origin[elt_is_mutable.value], element_trait: AnyTrait[AnyType], *element_types: element_trait]

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

Parameters

  • elt_is_mutable (Bool): True if the elements of the list are mutable for an mut or owned argument pack.
  • origin (Origin[elt_is_mutable.value]): The reference origin 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, UnknownDestructibility

Methods

__del__

__del__(owned self)

Destructor that releases elements if owned.

__getitem__

__getitem__[index: Int](self) -> ref [origin] element_types[index.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 Pointer'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) -> Int

Return the VariadicPack length.

Returns:

The number of elements in the variadic pack.

each

each[func: fn[element_trait]($0) capturing -> None](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 read-only 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)

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 read-only argument.

Parameters:

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