C# 7 Features - Tuples
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Tue Sep 6 04:08:25 PDT 2016
On Monday, 5 September 2016 at 15:50:31 UTC, Lodovico Giaretta
wrote:
> On Monday, 5 September 2016 at 15:43:43 UTC, Nick Treleaven
> wrote:
> We can already (almost do that):
>
> ========================================================
> import std.stdio, std.typecons;
>
> void unpack(T...)(Tuple!T tup, out T decls)
> {
> static if (tup.length > 0)
> {
> decls[0] = tup[0];
> tuple(tup[1..$]).unpack(decls[1..$]);
> }
> }
>
> void main()
> {
> auto t = tuple(1, "a", 3.0);
> int i;
> string s;
> double d;
> t.unpack(i, s, d);
> writeln(i);
> writeln(s);
> writeln(d);
> }
The main benefit of supporting tuple syntax is unpacking into new
declarations (writing Tuple!(...) or tuple!(...) isn't that
significant IMO). I was suggesting that out argument
*declarations* actually provides this and is a more general
feature.
More information about the Digitalmars-d
mailing list