dfor.hpp 527 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

4
5
#include <migraph/config.hpp>

6
7
namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
8
9
10
11

// Multidimensional for loop
inline auto dfor()
{
Paul's avatar
Paul committed
12
    return [](auto f) { f(); };
Paul's avatar
Paul committed
13
14
}

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

26
} // namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
27
} // namespace migraph
Paul's avatar
Paul committed
28
29

#endif