dfor.hpp 422 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef RTG_GUARD_RTGLIB_DFOR_HPP
#define RTG_GUARD_RTGLIB_DFOR_HPP

namespace rtg {

// Multidimensional for loop
inline auto dfor()
{
    return [](auto f)
    {
        f();
    };
}

template<class T, class... Ts>
auto dfor(T x, Ts... xs)
{
    return [=](auto f) 
    {
        for(T i = 0; i < x; i++)
        {
            dfor(xs...)([&](Ts... is) { f(i, is...); });
        }
    };
}

} // namespace rtg

#endif