Is unpacking variadic arguments coming soon?

At the moment, variadic arguments can be passed to other functions via VariadicList and the like. However, this approach fails if the second function is more general. An example:
@value
@register_passable("trivial")
struct MyType(Stringable):
fn __str__(self) -> String:
return "MyType"

fn do_stuff(self):
pass

fn func2[T: Stringable](args: VariadicListMem[T]):
for i in range(len(args)):
print(str(args[i]))

fn func1(args: VariadicListMem[MyType]):
for arg in args:
arg[].do_stuff()
func2(args)

fn func(*args: MyType):
func1(args)
@value
@register_passable("trivial")
struct MyType(Stringable):
fn __str__(self) -> String:
return "MyType"

fn do_stuff(self):
pass

fn func2[T: Stringable](args: VariadicListMem[T]):
for i in range(len(args)):
print(str(args[i]))

fn func1(args: VariadicListMem[MyType]):
for arg in args:
arg[].do_stuff()
func2(args)

fn func(*args: MyType):
func1(args)
Here, args is a VariadicList and cannot be passed as VariadicListMem. Using VariadicListMem in func2 does not work, however, since Stringable is not register passable. Making a register passable Stringable trait, in turn, is not possible, because AnyTrivialRegType is not trait and cannot be inherited from. I run into a similar issue if I use the (actually preferred) version that is fully parametric:
trait MyTypeTrait(Stringable):
fn do_stuff(self):
...

@value
struct MyType(MyTypeTrait):
fn __str__(self) -> String:
return "MyType"

fn do_stuff(self):
pass

fn func2[*Ts: Stringable](args: VariadicPack[_, Stringable, *Ts]):
@parameter
for i in range(args.__len__()):
print(str(args[i]))

fn func1[*Ts: MyTypeTrait](args: VariadicPack[_, MyTypeTrait, *Ts]):
@parameter
for i in range(args.__len__()):
args[i].do_stuff()
func2(args)

fn func[*Ts: MyTypeTrait](*args: *Ts):
func1(args)

fn main():
func(MyType(), MyType())
trait MyTypeTrait(Stringable):
fn do_stuff(self):
...

@value
struct MyType(MyTypeTrait):
fn __str__(self) -> String:
return "MyType"

fn do_stuff(self):
pass

fn func2[*Ts: Stringable](args: VariadicPack[_, Stringable, *Ts]):
@parameter
for i in range(args.__len__()):
print(str(args[i]))

fn func1[*Ts: MyTypeTrait](args: VariadicPack[_, MyTypeTrait, *Ts]):
@parameter
for i in range(args.__len__()):
args[i].do_stuff()
func2(args)

fn func[*Ts: MyTypeTrait](*args: *Ts):
func1(args)

fn main():
func(MyType(), MyType())
Here, the general function cannot take the more specific variadic pack. I understand if everyone is tired of the "when will XY be implemented" questions. However, for me the question is whether I have to build a big workaround (if it takes longer) or simply use duplicate code (if this can be fixed soon). Any advice (or alternative solutions)?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server