requires.hpp 1.68 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

#include <type_traits>
5
#include <migraph/config.hpp>
Paul's avatar
Paul committed
6

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

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

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

Paul's avatar
Paul committed
17
template <int N>
18
19
20
21
struct requires_enum
{
    enum e
    {
Paul's avatar
Paul committed
22
        a = 0
23
24
25
    };
};

Paul's avatar
Paul committed
26
#define MIGRAPH_REQUIRES_CAT(x, y) x##y
27

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

48
} // inline namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
49
} // namespace migraph
Paul's avatar
Paul committed
50
51

#endif