Multiple return values...
Martin Nowak
dawg at dawgfoto.de
Tue Mar 13 17:01:08 PDT 2012
>> Shall we discuss the shortcomings of his implementation? Can someone
>> demonstrate the details of his implementation?
>> From the little examples up in the thread, it looked like you could
>> only declare new variables inline, but not assign out to existing ones.
>> I'd say this needs to be added too, and perhaps that will throw the
>> whole design into turmoil? ;)
>
We already have very flexible assignments to existing variables.
import std.typecons, std.typetuple, std.stdio;
Tuple!(int, int) foo()
{
return typeof(return)(1, 2);
}
void main()
{
int a, b;
TypeTuple!(a, b) = foo();
writeln(a, b);
TypeTuple!(a, b) = tuple(0, 1, 2)[0 .. 2];
writeln(a, b);
Tuple!(int, int) t;
t[] = TypeTuple!(a, b);
writeln(t);
TypeTuple!(a, b) = tuple(t[1], t[0]);
writeln(a, b);
}
More information about the Digitalmars-d
mailing list