开发者

Iterating over tuple of arrays

I'm trying to iterate over a tuple of arrays of different types, calling a function with each element. My current implementation is like this:

// Some T... is defined up here.

// ArrayTuple!(T) is a TypeTuple of arrays of each type in T.
ArrayTuple!(T) data;
void开发者_运维技巧 iterate(alias func, uint n = 0)()
{
    static if(n < T.length)
    {
        foreach(elem; data[n])
            func(elem);

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

And is used as such:

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

iterate!(foo)();

Works great for the most part, but a delegate template can't be passed for func. Any suggestions on an implementation which supports template functions with stack pointers?


What would be the type of the delegate's parameter? You can't take the address of a method template and get a delegate - you'd need to instantiate it with a type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜