"examples/vscode:/vscode.git/clone" did not exist on "352d96eb823bb51ce8a7ffad5761d4f7106be706"
integral_constant.hpp 1023 Bytes
Newer Older
1
2
3
#ifndef CK_INTEGRAL_CONSTANT_HPP
#define CK_INTEGRAL_CONSTANT_HPP

Chao Liu's avatar
Chao Liu committed
4
namespace ck {
5

Chao Liu's avatar
Chao Liu committed
6
template <class T, T v>
Chao Liu's avatar
Chao Liu committed
7
8
9
10
struct integral_constant
{
    static constexpr T value = v;
    typedef T value_type;
Chao Liu's avatar
Chao Liu committed
11
    typedef integral_constant type;
Chao Liu's avatar
Chao Liu committed
12
    __host__ __device__ constexpr operator value_type() const noexcept { return value; }
Chao Liu's avatar
Chao Liu committed
13
    __host__ __device__ constexpr value_type operator()() const noexcept { return value; }
Chao Liu's avatar
Chao Liu committed
14
};
15

Chao Liu's avatar
Chao Liu committed
16
template <class T, T X, T Y>
Chao Liu's avatar
Chao Liu committed
17
18
19
20
21
__host__ __device__ constexpr auto operator+(integral_constant<T, X>, integral_constant<T, Y>)
{
    return integral_constant<T, X + Y>{};
}

Chao Liu's avatar
Chao Liu committed
22
23
24
25
26
27
template <class T, T X, T Y>
__host__ __device__ constexpr auto operator*(integral_constant<T, X>, integral_constant<T, Y>)
{
    return integral_constant<T, X * Y>{};
}

Chao Liu's avatar
Chao Liu committed
28
29
template <index_t N>
using Number = integral_constant<index_t, N>;
30

Chao Liu's avatar
Chao Liu committed
31
32
33
34
35
36
37
38
39
40
template <class X, class Y>
struct is_same : public integral_constant<bool, false>
{
};

template <class X>
struct is_same<X, X> : public integral_constant<bool, true>
{
};

41
42
} // namespace ck
#endif