Skip to main content
Log in

Mojo struct

VariadicPack

@register_passable struct VariadicPack[elt_is_mutable: Bool, //, is_owned: Bool, origin: Origin[elt_is_mutable], 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.
  • is_owned (Bool): Whether the elements are owned by the pack. If so, the pack will release the elements when it is destroyed.
  • origin (Origin[elt_is_mutable]): The 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.