"vscode:/vscode.git/clone" did not exist on "efd1d25733fb22f4900698d86dd88599e7864102"
integral_constant.hpp 1.06 KB
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
11
12
13
14
15
16
17
struct integral_constant
{
    static constexpr T value = v;
    typedef T value_type;
    typedef integral_constant type; // using injected-class-name
    __host__ __device__ constexpr operator value_type() const noexcept { return value; }
    __host__ __device__ constexpr value_type operator()() const noexcept
    {
        return value;
    } // since c++14
};
18

Chao Liu's avatar
Chao Liu committed
19
template <class T, T X, T Y>
Chao Liu's avatar
Chao Liu committed
20
21
22
23
24
__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
25
26
27
28
29
30
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
31
32
template <index_t N>
using Number = integral_constant<index_t, N>;
33

Chao Liu's avatar
Chao Liu committed
34
35
36
37
38
39
40
41
42
43
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>
{
};

44
45
} // namespace ck
#endif