Foreach over tuple of arrays?

Philippe Sigaud philippe.sigaud at gmail.com
Mon Aug 8 12:31:06 PDT 2011


Hmm, I just saw your question on SO. Is that nearer to what you ask?
It uses a anonymous template function:


import std.typecons;

void act(alias fun, T...)(ref Tuple!T data)
{
    foreach(index, range; data.expand)
        foreach(ref element; range)
            fun(element);
}

void main()
{
    auto data = tuple([0,1,2,3], [3,2,1], [0,1]);

    writeln(data);

    act!( (i) { return i+1; })(data);

    writeln(data);
}


Philippe


More information about the Digitalmars-d-learn mailing list