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?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?