"vscode:/vscode.git/clone" did not exist on "a8ba923c873f9848d0f6453f3e2e3fa2dd1187dc"
functional2.hpp 978 Bytes
Newer Older
1
2
3
#ifndef CK_FUNCTIONAL2_HPP
#define CK_FUNCTIONAL2_HPP

Chao Liu's avatar
Chao Liu committed
4
5
#include "functional.hpp"
#include "Sequence.hpp"
6

7
8
namespace ck {

Chao Liu's avatar
Chao Liu committed
9
10
template <class>
struct static_for_impl;
11

Chao Liu's avatar
Chao Liu committed
12
13
template <index_t... Is>
struct static_for_impl<Sequence<Is...>>
14
15
{
    template <class F>
Chao Liu's avatar
Chao Liu committed
16
    __host__ __device__ constexpr void operator()(F f) const
17
    {
Chao Liu's avatar
Chao Liu committed
18
        swallow{(f(Number<Is>{}), 0)...};
19
20
21
    }
};

Chao Liu's avatar
Chao Liu committed
22
23
24
// F signature: F(Number<Iter>)
template <index_t NBegin, index_t NEnd, index_t Increment>
struct static_for
25
{
26
    __host__ __device__ constexpr static_for()
27
    {
Chao Liu's avatar
Chao Liu committed
28
29
30
        static_assert(NBegin <= NEnd, "wrongs! should have NBegin <= NEnd");
        static_assert((NEnd - NBegin) % Increment == 0,
                      "Wrong! should satisfy (NEnd - NBegin) % Increment == 0");
31
    }
32

33
34
35
    template <class F>
    __host__ __device__ constexpr void operator()(F f) const
    {
Chao Liu's avatar
Chao Liu committed
36
        static_for_impl<typename arithmetic_sequence_gen<NBegin, NEnd, Increment>::type>{}(f);
37
38
39
    }
};

40
41
} // namespace ck
#endif