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](self: Reference[Tuple[element_types], is_mutable, lifetime, 0]) -> ref [$2] element_types[$0.value]
Get a reference to an element in the tuple.
Parameters:
- idx (
Int
): The element to return.
Returns:
A referece to the specified element.
__contains__
__contains__[T: EqualityComparable](self: Self, value: T) -> Bool
Verify if a given value is present in the tuple.
var x = Tuple(1,2,True)
if 1 in x: print("x contains 1")
Parameters:
- T (
EqualityComparable
): The type of the value argument. Must implement the traitEqualityComparable
.
Args:
- value (
T
): The value to find.
Returns:
True if the value is contained in the tuple, False otherwise.
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.