requires.hpp 1.16 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_REQUIRES_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_REQUIRES_HPP
Paul's avatar
Paul committed
3
4
5

#include <type_traits>

Paul's avatar
Paul committed
6
namespace migraph {
Paul's avatar
Paul committed
7

Paul's avatar
Paul committed
8
template <bool... Bs>
Paul's avatar
Paul committed
9
struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT
Paul's avatar
Paul committed
10
11
{
};
Paul's avatar
Paul committed
12

Paul's avatar
Paul committed
13
template <bool B>
Paul's avatar
Paul committed
14
15
using bool_c = std::integral_constant<bool, B>;

16
17
18
19
20
21
22
23
24
25
26
template<int N>
struct requires_enum
{
    enum e
    {
        A = 0
    };
};

#define MIGRAPH_REQUIRES_CAT(x, y) x ## y

Paul's avatar
Paul committed
27
#ifdef CPPCHECK
Paul's avatar
Paul committed
28
#define MIGRAPH_REQUIRES(...) class = void
Paul's avatar
Paul committed
29
#else
30
31
#if 0
// TODO: This current crashed on clang
Paul's avatar
Paul committed
32
#define MIGRAPH_REQUIRES(...)              \
33
34
35
36
37
38
39
        typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
         class = typename std::enable_if<and_<__VA_ARGS__, MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) == migraph::requires_enum<__LINE__>::A>{}>::type
#else
#define MIGRAPH_REQUIRES(...)              \
        typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
         class = typename std::enable_if<and_<__VA_ARGS__>{}>::type
#endif
Paul's avatar
Paul committed
40
#endif
Paul's avatar
Paul committed
41

Paul's avatar
Paul committed
42
} // namespace migraph
Paul's avatar
Paul committed
43
44

#endif