Foreach over tuple of arrays?

Sean Eskapp eatingstaples at gmail.com
Sun Aug 7 13:08:10 PDT 2011


I have a tuple of arrays of different types, but want to call a template
function on each element. How would I do this?

    void foo(T)(T elem)
    {
        ...
    }

I tried like this:

    ArrayTuple!(T) data;
    void iterate(alias func, uint n)()
    {
        static if(n < T.length)
        {
            foreach(elem; data[n])
                func(elem);

            iterate!(func, n + 1)();
        }
    }

Used like this:

    iterate!(foo, 0)();

This doesn't work when passing a delegate as func, however. Is there a way to
circumvent this?


More information about the Digitalmars-d-learn mailing list