Multiple return values...
bearophile
bearophileHUGS at lycos.com
Sat Mar 10 07:58:30 PST 2012
Robert Jacques:
> The proposed unpacking syntax, IIRC, was:
>
> (double a, int b) = fun();
>
> which lowered to:
>
> auto __tup = fun();
> double x = __tup[0]; // __tup[0] has a type that is implicitly convertible to double
> int y = __tup[1]; // ditto
>
> Why not instead lower to:
>
> auto __tup = fun();
> double x = __tup.tupleof[0];
> int y = __tup.tupleof[1];
The advange of lowering it to:
> auto __tup = fun();
> double x = __tup[0];
Is that it works with this too:
int[2] foo() { return [10,20; }
auto (x,y) = foo();
This case is quite common.
Bye,
bearophile
More information about the Digitalmars-d
mailing list