Consider I have two or more Tuples in a struct.
from std.reflection import get_type_name
def work_with_tuple[*elems: Movable](obj: Tuple[*elems]):
print(get_type_name[type_of(obj)]())
struct Container[
Tuple1: Copyable,
Tuple2: Copyable,
](ImplicitlyCopyable):
def __init__(out self, v1: Self.Tuple1, v2: Self.Tuple2):
work_with_tuple(v1)
def main():
Container((1,2), (3,4,5))
This, however creates a
tmp.mojo:11:9: error: invalid call to 'work_with_tuple': value passed to 'obj' cannot be converted from 'Tuple1' to 'Tuple[elems]', it depends on an unresolved parameter 'elems'
work_with_tuple(v1)
^~~~~~~~~~~~~~~ ~~
/home/cloud/tmp.mojo:3:5: note: function declared here
def work_with_tuple[*elems: Movable](obj: Tuple[*elems]):
You can have something like the following
struct Container[
# Tuple1: Copyable,
Tuple2: Copyable,
](ImplicitlyCopyable):
def __init__[*elems: Movable](out self, v1: Tuple[*elems], v2: Self.Tuple2):
work_with_tuple(v1)
# work_with_tuple(v2)
Then v1 can work_with_tuple, but v2 still not. You cannot have Tuple1 type now as it is dis-associated with the ctor, but you can comptime Tuple1 = Tuple[*Self.elems] by moving the elems to struct parameter.
But how to deal with v2 then? You cannot have two ‘*’ markers in the same parameter list.