AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Logical.hpp
1#pragma once
2
3// std c++ headers
4#include <tuple>
5#include <type_traits>
6#include <utility>
7
8namespace AMDiS
9{
11 template <bool B>
12 using bool_t = std::integral_constant<bool, B>;
13
15 template <bool B>
16 constexpr bool_t<B> bool_ = {};
17
18 // some boolean operations
19 // ---------------------------------------------------------------------------
20
21 template <bool... Bs>
22 constexpr bool all_of_v = (Bs && ...);
23
24 template <bool... Bs>
25 using all_of_t = bool_t<all_of_v<Bs...>>;
26
27 template <bool... Bs>
28 using and_t = all_of_t<Bs...>;
29
30 template <bool... Bs>
31 constexpr bool any_of_v = (Bs || ...);
32
33 template <bool... Bs>
34 using any_of_t = bool_t<any_of_v<Bs...>>;
35
36 template <bool... Bs>
37 using or_t = any_of_t<Bs...>;
38
39 template <bool... Bs>
40 constexpr bool none_of_v = !(Bs || ...);
41
42 template <bool... Bs>
43 using none_of_t = bool_t<none_of_v<Bs...>>;
44
45
46 template <bool... Bs>
47 constexpr all_of_t<Bs...> and_ = {};
48
49 template <bool B0, bool B1>
50 constexpr bool_t<B0 && B1> operator&&(bool_t<B0>, bool_t<B1>) { return {}; }
51
52
53 template <bool... Bs>
54 constexpr any_of_t<Bs...> or_ = {};
55
56 template <bool B0, bool B1>
57 constexpr bool_t<B0 || B1> operator||(bool_t<B0>, bool_t<B1>) { return {}; }
58
59
60 template <bool B>
61 using not_t = bool_t<!B>;
62
63 template <bool B>
64 constexpr bool_t<!B> not_ = {};
65
66 template <bool B>
67 constexpr bool_t<!B> operator!(bool_t<B>) { return {}; }
68
69
70 namespace Impl
71 {
72 template <class T, T... Is>
73 struct IsEqualImpl;
74
75 template <class T, T I0, T... Is>
76 struct IsEqualImpl<T, I0, Is...>
77 : public std::is_same<std::integer_sequence<T,I0,Is...>,
78 std::integer_sequence<T,Is...,I0>> {};
79
80 template <class T>
81 struct IsEqualImpl<T> { enum { value = true }; };
82
83 } // end namespace Impl
84
85 template <class T, T... values>
86 using IsEqual = Impl::IsEqualImpl<T,values...>;
87
88 template <class T, class... Ts>
89 using is_one_of = or_t<std::is_same_v<T, Ts>...>;
90
91} // end namespace AMDiS