Mojo struct
VariadicListMem
struct VariadicListMem[elt_is_mutable: Bool, _mlir_origin: LITOrigin[elt_is_mutable._mlir_value], origin: Origin[mut=elt_is_mutable], //, element_type: AnyType, is_owned: Bool]
A utility class to access variadic function arguments of memory-only types that may have ownership. It exposes references to the elements in a way that can be enumerated. Each element may be accessed with elt[].
Parameters
- elt_is_mutable (
Bool): True if the elements of the list are mutable for an mut or owned argument. - origin (
Origin): The origin of the underlying elements. - element_type (
AnyType): The type of the elements in the list. - is_owned (
Bool): Whether the elements are owned by the list because they are passed as an 'var' argument.
Fields
- value (
Variadic[ref[_mlir_origin] element_type]): The underlying storage, a variadic list of references to elements of the given type.
Implemented traits
AnyType,
ImplicitlyDestructible,
Movable,
Sized
comptime members
__del__is_trivial
comptime __del__is_trivial = False
__moveinit__is_trivial
comptime __moveinit__is_trivial = True
reference_type
comptime reference_type = Pointer[element_type, origin]
The pointer type for references to elements.
Methods
__del__
__del__(deinit self)
Destructor that releases elements if owned.
__getitem__
__getitem__(self, idx: Int) -> ref[origin, *[0,0]] element_type
Gets a single element on the variadic list.
Args:
- idx (
Int): The index of the element to access on the list.
Returns:
ref: A low-level pointer to the element on the list corresponding to the
given index.
consume_elements
consume_elements[elt_handler: fn(idx: Int, var elt: element_type) capturing -> None](deinit self)
Consume the variadic list by transferring ownership of each element into the provided closure one at a time. This is only valid on 'owned' variadic lists.
Parameters:
- elt_handler (
fn(idx: Int, var elt: element_type) capturing -> None): A function that will be called for each element of the list.
__len__
__len__(self) -> Int
Gets the size of the list.
Returns:
Int: The number of elements on the variadic list.
__iter__
__iter__(self) -> _VariadicListMemIter[element_type, origin, origin_of(self), is_owned]
Iterate over the list.
Returns:
_VariadicListMemIter: An iterator to the start of the list.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!