1#ifndef __DUNE_ACFEM_MPL_COMPARE_HH__
2#define __DUNE_ACFEM_MPL_COMPARE_HH__
7#include "../common/types.hh"
8#include "accumulate.hh"
28 template<
class T0, T0 t0,
class T1, T1 t1>
29 constexpr bool operator==(Constant<T0, t0>, Constant<T1, t1>)
34 template<
class T0, T0 t0,
class T1, T1 t1>
35 constexpr bool operator!=(Constant<T0, t0>, Constant<T1, t1>)
40 template<
class T0, T0 t0,
class T1, T1 t1>
41 constexpr bool operator<=(Constant<T0, t0>, Constant<T1, t1>)
46 template<
class T0, T0 t0,
class T1, T1 t1>
47 constexpr bool operator<(Constant<T0, t0>, Constant<T1, t1>)
52 template<
class T0, T0 t0,
class T1, T1 t1>
53 constexpr bool operator>(Constant<T0, t0>, Constant<T1, t1>)
58 template<
class T0, T0 t0,
class T1, T1 t1>
59 constexpr bool operator>=(Constant<T0, t0>, Constant<T1, t1>)
64 template<
class T0, T0 V0,
class T1, T1... V1>
65 constexpr bool operator==(Constant<T0, V0>, Sequence<T1, V1...>)
67 return (... && (V0 == V1));
70 template<
class T0, T0 V0,
class T1, T1... V1>
71 constexpr bool operator!=(Constant<T0, V0>, Sequence<T1, V1...>)
73 return (... || (V0 != V1));
76 template<
class T0, T0 V0,
class T1, T1... V1>
77 constexpr bool operator<=(Constant<T0, V0>, Sequence<T1, V1...>)
79 return (... && (V0 <= V1));
82 template<
class T0, T0 V0,
class T1, T1... V1>
83 constexpr bool operator<(Constant<T0, V0>, Sequence<T1, V1...>)
85 return (... && (V0 < V1));
88 template<
class T0, T0 V0,
class T1, T1... V1>
89 constexpr bool operator>=(Constant<T0, V0>, Sequence<T1, V1...>)
91 return (... && (V0 >= V1));
94 template<
class T0, T0 V0,
class T1, T1... V1>
95 constexpr bool operator>(Constant<T0, V0>, Sequence<T1, V1...>)
97 return (... && (V0 > V1));
100 template<
class T0, T0... V0,
class T1, T1 V1>
101 constexpr bool operator==(Sequence<T0, V0...>, Constant<T1, V1>)
103 return (... && (V0 == V1));
106 template<
class T0, T0... V0,
class T1, T1 V1>
107 constexpr bool operator!=(Sequence<T0, V0...>, Constant<T1, V1>)
109 return (... || (V0 != V1));
112 template<
class T0, T0... V0,
class T1, T1 V1>
113 constexpr bool operator<=(Sequence<T0, V0...>, Constant<T1, V1>)
115 return (... && (V0 <= V1));
118 template<
class T0, T0... V0,
class T1, T1 V1>
119 constexpr bool operator<(Sequence<T0, V0...>, Constant<T1, V1>)
121 return (... && (V0 < V1));
124 template<
class T0, T0... V0,
class T1>
125 constexpr bool operator<(Sequence<T0, V0...>, T1 t1)
127 return (... && (V0 < t1));
130 template<
class T0, T0... V0,
class T1, T1 V1>
131 constexpr bool operator>=(Sequence<T0, V0...>, Constant<T1, V1>)
133 return (... && (V0 >= V1));
136 template<
class T0, T0... V0,
class T1, T1 V1>
137 constexpr bool operator>(Sequence<T0, V0...>, Constant<T1, V1>)
139 return (... && (V0 > V1));
142 template<
class T0, T0... V0,
class T1, T1... V1,
143 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
144 constexpr bool operator==(Sequence<T0, V0...>, Sequence<T1, V1...>)
146 return (... && (V0 == V1));
149 template<
class T0, T0... V0,
class T1, T1... V1,
150 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
151 constexpr bool operator!=(Sequence<T0, V0...>, Sequence<T1, V1...>)
153 return (... || (V0 != V1));
156 template<
class T0, T0... V0,
class T1, T1... V1,
157 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
158 constexpr bool operator<=(Sequence<T0, V0...>, Sequence<T1, V1...>)
160 return (... && (V0 <= V1));
163 template<
class T0, T0... V0,
class T1, T1... V1,
164 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
165 constexpr bool operator<(Sequence<T0, V0...>, Sequence<T1, V1...>)
167 return (... && (V0 < V1));
170 template<
class T0, T0... V0,
class T1, T1... V1,
171 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
172 constexpr bool operator>=(Sequence<T0, V0...>, Sequence<T1, V1...>)
174 return (... && (V0 >= V1));
177 template<
class T0, T0... V0,
class T1, T1... V1,
178 std::enable_if_t<
sizeof...(V0) ==
sizeof...(V1),
int> = 0>
179 constexpr bool operator>(Sequence<T0, V0...>, Sequence<T1, V1...>)
181 return (... && (V0 > V1));
184 template<
class T0, T0... V0,
class T1, T1... V1,
185 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
186 constexpr bool operator==(Sequence<T0, V0...>, Sequence<T1, V1...>)
191 template<
class T0, T0... V0,
class T1, T1... V1,
192 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
193 constexpr bool operator!=(Sequence<T0, V0...>, Sequence<T1, V1...>)
198 template<
class T0, T0... V0,
class T1, T1... V1,
199 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
200 constexpr bool operator<=(Sequence<T0, V0...>, Sequence<T1, V1...>)
205 template<
class T0, T0... V0,
class T1, T1... V1,
206 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
207 constexpr bool operator<(Sequence<T0, V0...>, Sequence<T1, V1...>)
212 template<
class T0, T0... V0,
class T1, T1... V1,
213 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
214 constexpr bool operator>=(Sequence<T0, V0...>, Sequence<T1, V1...>)
219 template<
class T0, T0... V0,
class T1, T1... V1,
220 std::enable_if_t<
sizeof...(V0) !=
sizeof...(V1),
int> = 0>
221 constexpr bool operator>(Sequence<T0, V0...>, Sequence<T1, V1...>)
229 template<
class T1,
class T2,
class F,
class S,
230 std::enable_if_t<size<T1>() != size<T2>(),
int> = 0>
231 constexpr bool tupleCompareHelper(T1&&, T2&&, S, F&& f)
237 template<
class T1,
class T2,
class F, std::size_t... I>
238 constexpr bool tupleCompareHelper(T1&& t1, T2&& t2, IndexSequence<I...>, F&& f)
240 return (... && f(get<I>(std::forward<T1>(t1)), get<I>(std::forward<T2>(t2))));
245 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
246 constexpr bool operator==(T1&& t1, T2&& t2)
248 return tupleCompareHelper(std::forward<T1>(t1), std::forward<T2>(t2), MakeSequenceFor<T1>{}, [](
auto&& a,
auto&& b) {
return a == b; });
251 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
252 constexpr bool operator!=(T1&& t1, T2&& t2)
257 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
258 constexpr bool operator<=(T1&& t1, T2&& t2)
260 return tupleCompareHelper(std::forward<T1>(t1), std::forward<T2>(t2), MakeSequenceFor<T1>{}, [](
auto&& a,
auto&& b) {
return a <= b; });
263 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
264 constexpr bool operator<(T1&& t1, T2&& t2)
266 return tupleCompareHelper(std::forward<T1>(t1), std::forward<T2>(t2), MakeSequenceFor<T1>{}, [](
auto&& a,
auto&& b) {
return a < b; });
269 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
270 constexpr bool operator>=(T1&& t1, T2&& t2)
272 return tupleCompareHelper(std::forward<T1>(t1), std::forward<T2>(t2), MakeSequenceFor<T1>{}, [](
auto&& a,
auto&& b) {
return a >= b; });
275 template<class T1, class T2, std::enable_if_t<AllowsGet<T1>::value && AllowsGet<T2>::value,
int> = 0>
276 constexpr bool operator>(T1&& t1, T2&& t2)
278 return tupleCompareHelper(std::forward<T1>(t1), std::forward<T2>(t2), MakeSequenceFor<T1>{}, [](
auto&& a,
auto&& b) {
return a > b; });
284 template<
class T, T T0, T... Ts>
287 return (... && (T0 == Ts));
301 template<
class T, T I, T... Rest>
317 template<
template<std::
size_t, std::
size_t>
class DoSwap,
class T, T... Ts>
320 return IsSortedV<
Sequence<T, Ts...>, DoSwap>;
324 template<
class T, T... Ts>
327 return isSorted<DefaultDoSwap>(seq);
333 template<
class T, T... V>
342 template<std::size_t Align,
class T, T V0, T... V>
345 constexpr std::size_t start = V0/Align*Align;
346 constexpr std::size_t
size = (1+
sizeof...(V))/Align*Align;
348 return std::is_same<MakeSequence<T, size, start>,
Sequence<T, V0, V...> >::value;
351 template<std::
size_t Align,
class T>
352 constexpr bool isAlignedBlock(Sequence<T>, IndexConstant<Align> = IndexConstant<Align>{})
361 template<std::size_t... Ind>
364 constexpr std::size_t
size =
sizeof...(Ind);
365 return (... &&(Ind >= 0)) && (... && (Ind <
size)) && ((0 + ... + Ind) == (
size-1)*
size/2);
372 return BoolConstant<(... && std::is_integral<std::decay_t<T> >{})>{};
380 template<
class T, std::
size_t N>
383 return std::is_integral<T>{};
387 template<
class T1,
class T2>
405 template<
class Tuple>
411 template<
class Tuple, std::size_t First, std::size_t... Rest>
414 return (... && (0 == get<First>(std::forward<Tuple>(t)) - get<Rest>(std::forward<Tuple>(t))));
420 template<class Tuple, std::enable_if_t<IsTupleLike<Tuple>::value,
int> = 0>
423 return isConstantTupleHelper(std::forward<Tuple>(t),
MakeIndexSequence<size<Tuple>()>{});
428 template<
class Tuple,
template<
class...>
class Predicate,
429 std::size_t start = 0,
430 std::size_t
size = size<Tuple>()>
431 struct PredicateMatchHelper
432 :
public ConditionalType<Predicate<TupleElement<start, Tuple> >::value,
434 PredicateMatchHelper<Tuple, Predicate, start+1> >
436 static constexpr std::ptrdiff_t index_ =
437 Predicate<TupleElement<start, Tuple> >::value ? start : PredicateMatchHelper<Tuple, Predicate, start+1>::index_;
440 template<
class Tuple,
template<
class...>
class Predicate, std::size_t
size>
441 struct PredicateMatchHelper<Tuple, Predicate,
size,
size>
444 static constexpr std::ptrdiff_t index_ = -1;
453 template<
class Tuple,
template<
class...>
class Predicate,
class... Rest>
457 template<
template<
class...>
class Predicate,
class... T>
461 template<
template<
class...>
class Predicate,
class... T>
465 template<
template<
class...>
class Predicate,
class... T>
469 template<std::size_t N,
template<
class...>
class Predicate,
class... T>
470 using NthIs = Predicate<TypePackElement<N, T...> >;
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
MakeSequence< std::size_t, N, Offset, Stride, Repeat > MakeIndexSequence
Make a sequence of std::size_t elements.
Definition: generators.hh:34
typename BuildSequence< T, N, Offset, Stride, Repeat >::Type MakeSequence
Make an index sequence with an optional offset.
Definition: makesequence.hh:197
Predicate< TypePackElement< N, T... > > NthIs
Instantiates to Predicate applied to the N-th element of T...
Definition: compare.hh:470
decltype(isIntegralTuple(std::declval< T >())) IsIntegralTuple
Decide whether the given tuple contains only integral types.
Definition: compare.hh:402
constexpr auto isIntegralTuple(const std::array< T, N > &)
Decide whether the given tuple contains only integral types.
Definition: compare.hh:381
BoolConstant<(... &&Predicate< T >::value)> AllAre
TrueType if all types match the predicate.
Definition: compare.hh:466
constexpr bool isConsecutive(Sequence< T, I, Rest... > seq)
Definition: compare.hh:302
IndexConstant< PredicateMatch< std::tuple< T... >, Predicate >::index_ > IndexOfMatching
Obtain the index of the first matching tuple type.
Definition: compare.hh:458
constexpr bool isSimple(Sequence< T, V... > seq)
Definition: compare.hh:334
constexpr bool isPermutation(IndexSequence< Ind... >=IndexSequence< Ind... >{})
Definition: compare.hh:362
constexpr bool isConstant(Sequence< T, T0, Ts... >)
Definition: compare.hh:285
decltype(isIntegralPack(std::declval< T >()...)) IsIntegralPack
Decide whether the given parameter pack contains only integral types.
Definition: compare.hh:377
constexpr bool isAlignedBlock(Sequence< T, V0, V... >, IndexConstant< Align >=IndexConstant< Align >{})
Definition: compare.hh:343
BoolConstant<(...||Predicate< T >::value)> AnyIs
TrueType if any type matches the predicate.
Definition: compare.hh:462
constexpr auto isIntegralPack(T &&...)
Decide whether the given parameter pack contains only integral types.
Definition: compare.hh:370
constexpr bool isSorted(Sequence< T, Ts... >)
Definition: compare.hh:318
PredicateMatchHelper< std::decay_t< Tuple >, PredicateProxy< Predicate, Rest... >::template ForwardFirst > PredicateMatch
Apply the predicate to each tuple type in turn.
Definition: compare.hh:454
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
std::integer_sequence< T, V... > Sequence
Sequence of any type of integer values.
Definition: types.hh:56
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
Wrap the given predicate class F into another one with spcial requirements.
Definition: types.hh:218