Logical.hpp 2.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once

// std c++ headers
#include <tuple>
#include <type_traits>
#include <utility>

namespace AMDiS
{
  /// A wrapper for bool types
  template <bool B>
  using bool_t  = std::integral_constant<bool, B>;

  /// Variable template to generate bool type
  template <bool B>
  constexpr bool_t<B> bool_ = {};

  // some boolean operations
  // ---------------------------------------------------------------------------

  namespace Impl
  {
    template <bool...> struct all_helper {};

  } // end namespace Impl

  template <bool... Bs>
  using all_of_t = std::is_same<Impl::all_helper<true, Bs...>, Impl::all_helper<Bs..., true>>;

  template <bool... Bs>
  constexpr bool all_of_v = all_of_t<Bs...>::value;

  template <bool... Bs>
  using and_t = all_of_t<Bs...>;

  template <bool... Bs>
  using none_of_t = std::is_same<Impl::all_helper<false, Bs...>, Impl::all_helper<Bs..., false>>;

  template <bool... Bs>
  constexpr bool none_of_v = none_of_t<Bs...>::value;

  template <bool... Bs>
  using any_of_t = bool_t<not none_of_t<Bs...>::value>;

  template <bool... Bs>
  constexpr bool any_of_v = any_of_t<Bs...>::value;

  template <bool... Bs>
  using or_t = any_of_t<Bs...>;


  template <bool... Bs>
  constexpr bool_t<and_t<Bs...>::value> and_ = {};

  template <bool B0, bool B1>
  constexpr bool_t<B0 && B1> operator&&(bool_t<B0>, bool_t<B1>) { return {}; }


  template <bool... Bs>
  constexpr bool_t<or_t<Bs...>::value> or_ = {};

  template <bool B0, bool B1>
  constexpr bool_t<B0 || B1> operator||(bool_t<B0>, bool_t<B1>) { return {}; }


  template <bool B>
  using not_t = bool_t<!B>;

  template <bool B>
  constexpr bool_t<not_t<B>::value> not_ = {};

  template <bool B>
  constexpr bool_t<!B> operator!(bool_t<B>) { return {}; }


  namespace Impl
  {
    template <class T, T... Is>
    struct IsEqualImpl;

    template <class T, T I0, T... Is>
    struct IsEqualImpl<T, I0, Is...>
        : public std::is_same<std::integer_sequence<T,I0,Is...>,
                              std::integer_sequence<T,Is...,I0>> {};

    template <class T>
    struct IsEqualImpl<T> { enum { value = true }; };

  } // end namespace Impl

  template <class T, T... values>
  using IsEqual = Impl::IsEqualImpl<T,values...>;

  template <class T, class... Ts>
95
  using is_one_of = or_t<std::is_same_v<T, Ts>...>;
96
97

} // end namespace AMDiS