Mojo struct
StaticTuple
@register_passable(trivial)
struct StaticTuple[element_type: AnyTrivialRegType, size: Int]
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
,
UnknownDestructibility
Methods
__init__
__init__(out self)
Constructs an empty (undefined) tuple.
__init__(out self, array: array<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "value">, element_type>)
Constructs from an array type.
Args:
- array (
array<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "value">, element_type>
): Underlying MLIR array type.
__init__(out self, *elems: element_type)
Constructs a static tuple given a set of arguments.
Args:
- *elems (
element_type
): The element types.
__init__(out self, values: VariadicList[element_type])
Creates a tuple constant using the specified values.
Args:
- values (
VariadicList[element_type]
): The list of values.
__init__(out self, *, other: Self)
Explicitly copy the provided StaticTuple.
Args:
- other (
Self
): The StaticTuple to copy.
__getitem__
__getitem__[index: Int](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__[IntLike: IntLike, //](self, idx: IntLike) -> element_type
Returns the value of the tuple at the given dynamic index.
Parameters:
- IntLike (
IntLike
): The type of idx; eitherInt
orUInt
.
Args:
- idx (
IntLike
): The index into the tuple.
Returns:
The value at the specified position.
__setitem__
__setitem__[IntLike: IntLike, //](mut self, idx: IntLike, val: element_type)
Stores a single value into the tuple at the specified dynamic index.
Parameters:
- IntLike (
IntLike
): The type of idx; eitherInt
orUInt
.
Args:
- idx (
IntLike
): The index into the tuple. - val (
element_type
): The value to store.
__setitem__[index: Int](mut 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.
__len__
__len__(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!