Skip to main content
Log in

Mojo struct

VariadicListMem

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 inout or owned argument.
  • element_type (AnyType): The type of the elements in the list.
  • lifetime (AnyLifetime[elt_is_mutable.value]): The reference lifetime of the underlying elements.

Aliases

  • reference_type = Reference[elt_is_mutable, element_type, lifetime, 0]:

Fields

  • value (variadic<!lit.ref<!kgen.paramref<:trait<@stdlib::@builtin::@anytype::@AnyType> element_type>, mut=#lit.struct.extract<:@stdlib::@builtin::@bool::@Bool elt_is_mutable, "value">, lifetime>, borrow_in_mem>): The underlying storage, a variadic list of references to elements of the given type.

Implemented traits

AnyType, Sized

Methods

__init__

__init__(inout self: Self, value: variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, borrow_in_mem>)

Constructs a VariadicList from a variadic argument type.

Args:

  • value (variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, borrow_in_mem>): The variadic argument to construct the list with.

__init__(inout self: Self, inout value: variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, inout>)

Constructs a VariadicList from a variadic argument type.

Args:

  • value (variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, inout>): The variadic argument to construct the list with.

__init__(inout self: Self, owned value: variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, owned_in_mem>)

Constructs a VariadicList from a variadic argument type.

Args:

  • value (variadic<!lit.ref<!kgen.paramref<:trait<_stdlib::_builtin::_anytype::_AnyType> element_type>, mut=#lit.struct.extract<:_stdlib::_builtin::_bool::_Bool elt_is_mutable, "value">, lifetime>, owned_in_mem>): The variadic argument to construct the list with.

__moveinit__

__moveinit__(inout self: Self, owned existing: Self)

Moves constructor.

Args:

  • existing (Self): The existing VariadicListMem.

__del__

__del__(owned self: Self)

Destructor that releases elements if owned.

__getitem__

__getitem__(self: Self, idx: Int) -> ref [{lifetime, (mutcast imm *[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:

A low-level pointer to the element on the list corresponding to the given index.

__len__

__len__(self: Self) -> Int

Gets the size of the list.

Returns:

The number of elements on the variadic list.

__iter__

__iter__(self: Self) -> _VariadicListMemIter[elt_is_mutable, element_type, lifetime, *[0,0]]

Iterate over the list.

Returns:

An iterator to the start of the list.

Was this page helpful?