"src/targets/vscode:/vscode.git/clone" did not exist on "d78bcdfb5f4d030e85ad81a8f42cb953b70c788d"
dfor.hpp 426 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_DFOR_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_DFOR_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
namespace migraph {
Paul's avatar
Paul committed
5
6
7
8

// Multidimensional for loop
inline auto dfor()
{
Paul's avatar
Paul committed
9
    return [](auto f) { f(); };
Paul's avatar
Paul committed
10
11
}

Paul's avatar
Paul committed
12
template <class T, class... Ts>
Paul's avatar
Paul committed
13
14
auto dfor(T x, Ts... xs)
{
Paul's avatar
Paul committed
15
    return [=](auto f) {
Paul's avatar
Paul committed
16
17
18
19
20
21
22
        for(T i = 0; i < x; i++)
        {
            dfor(xs...)([&](Ts... is) { f(i, is...); });
        }
    };
}

Paul's avatar
Paul committed
23
} // namespace migraph
Paul's avatar
Paul committed
24
25

#endif