Loading [MathJax]/extensions/TeX/AMSmath.js

DUNE-ACFEM (unstable)

conditionaljoin.hh
1#ifndef __DUNE_ACFEM_MPL_CONDITIONALJOIN_HH__
2#define __DUNE_ACFEM_MPL_CONDITIONALJOIN_HH__
3
4#include "compare.hh"
5
6namespace Dune {
7
8 namespace ACFem {
9
10 namespace TupleUtilities {
11
27 template<template<class...> class F, class Tuple, class E,
28 std::enable_if_t<(IsTupleLike<Tuple>::value
29 && PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
30 ), int> = 0>
31 constexpr auto pushBackIf(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
32 {
33 return std::tuple_cat(std::forward<Tuple>(t), std::tuple<E>(e));
34 }
35
37 template<template<class...> class F, class Tuple, class E,
38 std::enable_if_t<(IsTupleLike<Tuple>::value
39 && !PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
40 ), int> = 0>
41 constexpr auto pushBackIf(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
42 {
43 return std::forward<Tuple>(t);
44 }
45
51 template<template<class...> class F, class Tuple, class E,
52 std::enable_if_t<(IsTupleLike<Tuple>::value
53 && !PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
54 ), int> = 0>
55 constexpr auto pushBackUnless(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
56 {
57 return std::tuple_cat(std::forward<Tuple>(t), std::tuple<E>(e));
58 }
59
61 template<template<class...> class F, class Tuple, class E,
62 std::enable_if_t<(IsTupleLike<Tuple>::value
63 && PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
64 ), int> = 0>
65 constexpr auto pushBackUnless(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
66 {
67 return std::forward<Tuple>(t);
68 }
69
73 template<template<class...> class F, class Tuple, class E,
74 std::enable_if_t<(IsTupleLike<Tuple>::value
75 && PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
76 ), int> = 0>
77 constexpr auto addFrontIf(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
78 {
79 return std::tuple_cat(std::tuple<E>(e), std::forward<Tuple>(t));
80 }
81
83 template<template<class...> class F, class Tuple, class E,
84 std::enable_if_t<(IsTupleLike<Tuple>::value
85 && !PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
86 ), int> = 0>
87 constexpr auto addFrontIf(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
88 {
89 return std::forward<Tuple>(t);
90 }
91
95 template<template<class...> class F, class Tuple, class E,
96 std::enable_if_t<(IsTupleLike<Tuple>::value
97 && !PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
98 ), int> = 0>
99 constexpr auto addFrontUnless(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
100 {
101 return std::tuple_cat(std::tuple<E>(e), std::forward<Tuple>(t));
102 }
103
105 template<template<class...> class F, class Tuple, class E,
106 std::enable_if_t<(IsTupleLike<Tuple>::value
107 && PredicateMatch<Tuple, PredicateProxy<F, E>::template ForwardFirst>::value
108 ), int> = 0>
109 constexpr auto addFrontUnless(Tuple&& t, E&& e, PredicateWrapper<F> = PredicateWrapper<F>{})
110 {
111 return std::forward<Tuple>(t);
112 }
113
114 namespace {
115 template<std::size_t N, template<class...> class F, class T1, class T2,
116 std::enable_if_t<(N >= size<T2>()), int> = 0>
117 constexpr T1 joinIfHelper(T1&& t1, T2&& t2, IndexConstant<N> = IndexConstant<N>{})
118 {
119 return t1;
120 }
121
122 template<std::size_t N, template<class, class, class...> class F, class T1, class T2,
123 std::enable_if_t<(N < size<T2>()), int> = 0>
124 constexpr auto joinIfHelper(T1&& t1, T2&& t2, IndexConstant<N> = IndexConstant<N>{})
125 {
126 return joinIfHelper<N+1, F>(pushBackIf<F>(std::forward<T1>(t1), get<N>(std::forward<T2>(t2))),
127 std::forward<T2>(t2));
128 }
129
130 template<std::size_t N, template<class...> class F, class T1, class T2,
131 std::enable_if_t<(N >= size<T2>()), int> = 0>
132 constexpr T1 joinUnlessHelper(T1&& t1, T2&& t2, IndexConstant<N> = IndexConstant<N>{})
133 {
134 return std::forward<T1>(t1);
135 }
136
137 template<std::size_t N, template<class...> class F, class T1, class T2,
138 std::enable_if_t<(N < size<T2>()), int> = 0>
139 constexpr auto joinUnlessHelper(T1&& t1, T2&& t2, IndexConstant<N> = IndexConstant<N>{})
140 {
141 return joinUnlessHelper<N+1, F>(pushBackUnless<F>(std::forward<T1>(t1), get<N>(std::forward<T2>(t2))),
142 std::forward<T2>(t2));
143 }
144
145 } // NS anonymous
146
148 template<template<class...> class F, class T, class... Arg,
149 std::enable_if_t<(!IsAlwaysTrue<F>::value
150 && IsTupleLike<T>::value
151 && sizeof...(Arg) == 1
152 && size<decltype(joinIfHelper<0, F>(std::declval<T>(), std::declval<Arg>()...))>() > size<T>()
153 ), int> = 0>
154 constexpr auto joinIf(T&& t, Arg&&... arg)
155 {
156 return joinIfHelper<0, F>(std::forward<T>(t), std::forward<Arg>(arg)...);
157 }
158
162 template<template<class...> class F, class T, class... Arg,
163 std::enable_if_t<(!IsAlwaysTrue<F>::value
165 && sizeof...(Arg) == 1
166 && size<decltype(joinIfHelper<0, F>(std::declval<T>(), std::declval<Arg>()...))>() == size<T>()
167 ), int> = 0>
168 constexpr auto joinIf(T&& t, Arg&&...)
169 {
170 return std::forward<T>(t);
171 }
172
173 template<template<class...> class F, class T0, class T1, class... Arg,
174 std::enable_if_t<(!IsAlwaysTrue<F>::value
177 && sizeof...(Arg) >= 1), int> = 0>
178 constexpr auto joinIf(T0&& t0, T1&& t1, Arg&&... arg)
179 {
180 return joinIf<F>(joinIf<F>(std::forward<T0>(t0), std::forward<T1>(t1)), std::forward<Arg>(arg)...);
181 }
182
183 template<template<class...> class F, class T, class... Arg,
184 std::enable_if_t<(IsAlwaysTrue<F>::value
185 && IsTupleLike<T>::value
186 ), int> = 0>
187 constexpr auto joinIf(T&& t, Arg&&... arg)
188 {
189 return std::tuple_cat(std::forward<T>(t), std::forward<Arg>(arg)...);
190 }
191
193
195 template<template<class...> class F, class T, class... Arg,
196 std::enable_if_t<(!IsAlwaysFalse<F>::value
197 && IsTupleLike<T>::value
198 && sizeof...(Arg) == 1
199 && size<decltype(joinUnlessHelper<0, F>(std::declval<T>(), std::declval<Arg>()...))>() > size<T>()
200 ), int> = 0>
201 constexpr auto joinUnless(T&& t, Arg&&... arg)
202 {
203 return joinUnlessHelper<0, F>(std::forward<T>(t), std::forward<Arg>(arg)...);
204 }
205
209 template<template<class...> class F, class T, class... Arg,
210 std::enable_if_t<(!IsAlwaysFalse<F>::value
212 && sizeof...(Arg) == 1
213 && size<decltype(joinUnlessHelper<0, F>(std::declval<T>(), std::declval<Arg>()...))>() == size<T>()
214 ), int> = 0>
215 constexpr auto joinUnless(T&& t, Arg&&...)
216 {
217 return std::forward<T>(t);
218 }
219
220 template<template<class...> class F, class T0, class T1, class... Arg,
221 std::enable_if_t<(!IsAlwaysFalse<F>::value
224 && sizeof...(Arg) >= 1), int> = 0>
225 constexpr auto joinUnless(T0&& t0, T1&& t1, Arg&&... arg)
226 {
227 return joinUnless<F>(joinUnless<F>(std::forward<T0>(t0), std::forward<T1>(t1)), std::forward<Arg>(arg)...);
228 }
229
230 template<template<class...> class F, class T, class... Arg,
231 std::enable_if_t<(IsAlwaysFalse<F>::value
232 && IsTupleLike<T>::value
233 ), int> = 0>
234 constexpr auto joinUnless(T&& t, Arg&&... arg)
235 {
236 return std::tuple_cat(std::forward<T>(t), std::forward<Arg>(arg)...);
237 }
238
240
242
243 } // TupleUtilities
244
245 } // ACFem::
246
247} // Dune::
248
249#endif // __DUNE_ACFEM_MPL_CONDITIONALJOIN_HH__
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
constexpr auto addFrontIf(Tuple &&t, E &&e, PredicateWrapper< F >=PredicateWrapper< F >{})
Enforce kind of uniqueness.
Definition: conditionaljoin.hh:77
constexpr auto pushBackIf(Tuple &&t, E &&e, PredicateWrapper< F >=PredicateWrapper< F >{})
Enforce kind of uniqueness.
Definition: conditionaljoin.hh:31
constexpr auto joinIf(T &&t, Arg &&... arg)
Add the elements of Arg... in turn to T if the predicate F matches.
Definition: conditionaljoin.hh:154
constexpr auto joinUnless(T &&t, Arg &&... arg)
Add the elements of Arg... in turn to T if the predicate F matches.
Definition: conditionaljoin.hh:201
constexpr auto pushBackUnless(Tuple &&t, E &&e, PredicateWrapper< F >=PredicateWrapper< F >{})
Enforce kind of uniqueness.
Definition: conditionaljoin.hh:55
constexpr auto addFrontUnless(Tuple &&t, E &&e, PredicateWrapper< F >=PredicateWrapper< F >{})
Enforce kind of uniqueness.
Definition: conditionaljoin.hh:99
Assume a predicate is a traits-class and would never evaluate to false unless it is equivalent to Alw...
Definition: types.hh:183
Assume a predicate is a traits-class and would never evaluate to true unless it is equivalent to Alwa...
Definition: types.hh:167
Definition: types.hh:374
Wrap a predicate into a class which can be passed on as argument.
Definition: types.hh:264
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)