Mojo struct
Tuple
The type of a literal tuple expression.
A tuple consists of zero or more values, separated by commas.
Parametersβ
- β*element_types (
Movable
): The elements type.
Fieldsβ
- βstorage (
!kgen.pack<:variadic<trait<@stdlib::@builtin::@value::@Movable>> element_types>
): The underlying storage for the tuple.
Implemented traitsβ
AnyType
,
Movable
,
Sized
Methodsβ
__init__
β
__init__(inout self: Self, owned *args: *element_types)
Construct the tuple.
Args:
- β*args (
*element_types
): Initial values.
__init__(inout self: Self, *, owned storage: VariadicPack[elt_is_mutable, lifetime, Movable, element_types])
Construct the tuple from a low-level internal representation.
Args:
- βstorage (
VariadicPack[elt_is_mutable, lifetime, Movable, element_types]
): The variadic pack storage to construct from.
__moveinit__
β
__moveinit__(inout self: Self, owned existing: Self)
Move construct the tuple.
Args:
- βexisting (
Self
): The value to move from.
__del__
β
__del__(owned self: Self)
Destructor that destroys all of the elements.
__getitem__
β
__getitem__[idx: Int](ref [self_is_lifetime] self: Self) -> ref [_] element_types[$0.value]
Get a reference to an element in the tuple.
Parameters:
- βidx (
Int
): The element to return.
Returns:
A reference to the specified element.
__contains__
β
__contains__[T: EqualityComparable](self: Self, value: T) -> Bool
Return whether the tuple contains the specified value.
For example:
var t = Tuple(True, 1, 2.5)
if 1 in t:
print("t contains 1")
var t = Tuple(True, 1, 2.5)
if 1 in t:
print("t contains 1")
Parameters:
- βT (
EqualityComparable
): The type of the value.
Args:
- βvalue (
T
): The value to search for.
Returns:
True if the value is in the tuple, False otherwise.
__len__
β
static __len__() -> Int
Return the number of elements in the tuple.
Returns:
The tuple length.
__len__(self: Self) -> Int
Get the number of elements in the tuple.
Returns:
The tuple length.
get
β
get[i: Int, T: Movable](self: Self) -> ref [*[0,0]] $1
Get a tuple element and rebind to the specified type.
Parameters:
- βi (
Int
): The element index. - βT (
Movable
): The element type.
Returns:
The tuple element at the requested index.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?