Skip to main content

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.

Implemented traits

AnyType, Defaultable, ExplicitlyCopyable, ImplicitlyCopyable, Movable, Sized, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = True

__del__is_trivial

alias __del__is_trivial = True

__moveinit__is_trivial

alias __moveinit__is_trivial = True

Methods

__init__

__init__() -> Self

Constructs an empty (undefined) tuple.

__init__(*, mlir_value: array<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "_mlir_value">, element_type>) -> Self

Constructs from an array type.

Args:

  • mlir_value (array<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "_mlir_value">, element_type>): Underlying MLIR array type.

__init__(*, fill: element_type) -> Self

Constructs a static tuple given a fill value.

Args:

  • fill (element_type): The value to fill the tuple with.

__init__(*elems: element_type) -> Self

Constructs a static tuple given a set of arguments.

Args:

  • *elems (element_type): The element types.

__init__(values: VariadicList[element_type]) -> Self

Creates a tuple constant using the specified values.

Args:

__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:

element_type: The value at the specified position.

__getitem__[I: Indexer, //](self, idx: I) -> element_type

Returns the value of the tuple at the given dynamic index.

Parameters:

  • I (Indexer): A type that can be used as an index.

Args:

  • idx (I): The index into the tuple.

Returns:

element_type: The value at the specified position.

__setitem__

__setitem__[I: Indexer, //](mut self, idx: I, val: element_type)

Stores a single value into the tuple at the specified dynamic index.

Parameters:

  • I (Indexer): A type that can be used as an index.

Args:

  • idx (I): The index into the tuple.
  • val (element_type): The value to store.

__setitem__[idx: Int](mut self, val: element_type)

Stores a single value into the tuple at the specified index.

Parameters:

  • idx (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:

Int: The size of the list.

Was this page helpful?