Mojo struct
StaticTuple
A statically sized tuple type which contains elements of homogeneous types.
Parametersβ
- βelement_type (
AnyTrivialRegType
): The type of the elements in the tuple. - βsize (
Int
): The size of the tuple.
Aliasesβ
type = array<#lit.struct.extract<:@stdlib::@builtin::@int::@Int size, "value">, element_type>
:
Fieldsβ
- βarray (
array<#lit.struct.extract<:@stdlib::@builtin::@int::@Int size, "value">, element_type>
): The underlying storage for the static tuple.
Implemented traitsβ
AnyType
,
Copyable
,
Movable
,
Sized
Methodsβ
__init__
β
__init__(inout self: Self)
Constructs an empty (undefined) tuple.
__init__(inout self: Self, *elems: element_type)
Constructs a static tuple given a set of arguments.
Args:
- β*elems (
element_type
): The element types.
__init__(inout self: Self, values: VariadicList[element_type])
Creates a tuple constant using the specified values.
Args:
- βvalues (
VariadicList[element_type]
): The list of values.
__init__(inout self: Self, *, other: Self)
Explicitly copy the provided StaticTuple.
Args:
- βother (
Self
): The StaticTuple to copy.
__getitem__
β
__getitem__[index: Int](self: Self) -> element_type
Returns the value of the tuple at the given index.
Parameters:
- βindex (
Int
): The index into the tuple.
Returns:
The value at the specified position.
__getitem__(self: Self, idx: Int) -> element_type
Returns the value of the tuple at the given dynamic index.
Args:
- βidx (
Int
): The index into the tuple.
Returns:
The value at the specified position.
__setitem__
β
__setitem__[index: Int](inout self: Self, val: element_type)
Stores a single value into the tuple at the specified index.
Parameters:
- βindex (
Int
): The index into the tuple.
Args:
- βval (
element_type
): The value to store.
__setitem__(inout self: Self, idx: Int, val: element_type)
Stores a single value into the tuple at the specified dynamic index.
Args:
- βidx (
Int
): The index into the tuple. - βval (
element_type
): The value to store.
__len__
β
__len__(self: Self) -> Int
Returns the length of the array. This is a known constant value.
Returns:
The size of the list.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?