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.

Reply via email to