dfor.hpp 534 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
6
#include <migraph/config.hpp>

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

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

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

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

#endif