Tuple issue
monkyyy
crazymonkyyy at gmail.com
Sun Nov 15 19:45:48 UTC 2026
On Sunday, 15 November 2026 at 19:29:32 UTC, DLearner wrote:
> Hi
>
> Please see (under -betterC):
> ```
> extern(C) void main() {
>
> import std.typecons;
>
> int Arg1, Arg2;
>
> Tuple!(int, int) fnTuple1(int Parm) {
>
> int retval1;
> int retval2;
>
>
> retval1 = 2*Parm;
> retval2 = 3*Parm;
>
> return tuple(retval1, retval2);
> }
>
>
> tuple(Arg1, Arg2) = fnTuple1(4);
>
> assert(Arg1 == 0);
> assert(Arg2 == 0);
>
> assert(Arg1 == 8);
> assert(Arg2 == 12);
> }
>
>
> ```
>
> Expected: Assert failure on Arg1 == 0 (because value actually 8)
> Actual: Assert failure on Arg1 == 8.
>
> Suggestions (without having to name a tuple variable)?
tuple is a constructor for Tuple not a destructurer
you should either use the names or make your own(the std one is
fucking huge)
conspectually all you need is:
```d
struct Tuple(T...){
T expand;
}
auto tuple(T...)(T args)=>Tuple!T(args);
```
if you add a `foreach(I;0..T.length){ mixin( "ref
_"~I.to!string"~()=>expand[I];")}
youll get the syntax to store multiple returns in auto foo and
you destructure with foo._0
More information about the Digitalmars-d-learn
mailing list