DUNE-ACFEM (unstable)

types.hh
1#ifndef __DUNE_ACFEM_COMMON_TYPES_HH__
2#define __DUNE_ACFEM_COMMON_TYPES_HH__
3
4#include <limits>
5#include <utility>
6#include <cstdint>
7#include <cstddef>
8#include <tuple>
9#include <array>
10
11#include "compiler.hh"
12#include "../mpl/conditional.hh"
13
14#include "../core-fixes.hh"
15
16namespace Dune {
17
18 namespace ACFem {
19
30 template<class T, T V>
31 struct integral_constant
32 {
33 using value_type = T;
34 static constexpr T value = V;
35 constexpr value_type operator()() const { return value; }
36 };
37
39 template<class T, T V>
40 using Constant = integral_constant<T, V>;
41
43 template<std::size_t V>
45
47 template<bool V>
49
51 template<std::ptrdiff_t V>
53
55 template<class T, T... V>
56 using Sequence = std::integer_sequence<T, V...>;
57
59 template<bool... Decisions>
60 using BoolSequence = Sequence<bool, Decisions...>;
61
63 template<std::size_t... V>
64 using IndexSequence = Sequence<std::size_t, V...>;
65
67 template<std::ptrdiff_t... V>
68 using IntSequence = Sequence<std::ptrdiff_t, V...>;
69
71
78 template<class Const>
80
82 template<class Const>
83 using Decr = Constant<typename Const::value_type, Const::value - 1>;
84
86
93 template<class T>
94 using IsDecay = std::is_same<T, std::decay_t<T> >;
95
97 template<class T1, class T2>
98 using HasSameDecay = std::is_same<std::decay_t<T1>, std::decay_t<T2> >;
99
103 template<class Base, class Derived> using
104 IsBaseOfDecay = std::is_base_of<std::decay_t<Base>, std::decay_t<Derived> >;
105
108
111
113 constexpr auto trueType() { return TrueType{}; }
114
116 constexpr auto falseType() { return FalseType{}; }
117
119 template<bool Cond>
120 constexpr auto boolType(BoolConstant<Cond> arg = BoolConstant<Cond>{}) { return arg; }
121
123 template<class T0, class T1>
124 constexpr auto forwardAsPair(T0&& t0, T1&& t1)
125 {
126 return std::pair<T0, T1>(std::forward<T0>(t0), std::forward<T1>(t1));
127 }
128
130 template<class T>
131 using RefersConst = BoolConstant<(std::is_const<T>::value
132 ||
133 std::is_const<std::remove_reference_t<T> >::value)>;
134
139 template<class T, class... Other>
140 struct MakeType
141 {
142 using Type = T;
143 };
144
146 template<class... T>
147 using FirstType = typename MakeType<T...>::Type;
148
150 template<class... Other>
151 using VoidType = typename MakeType<void, Other...>::Type;
152
154 template<class... Other>
155 using AlwaysFalse = typename MakeType<FalseType, Other...>::Type;
156
158 template<class... Other>
159 using AlwaysTrue = typename MakeType<TrueType, Other...>::Type;
160
164 template<template<class...> class Predicate, class SFINAE = void>
166 : FalseType
167 {};
168
172 template<template<class...> class Predicate>
173 struct IsAlwaysTrue<Predicate, std::enable_if_t<Predicate<>::value> >
174 : TrueType
175 {};
176
180 template<template<class...> class Predicate, class SFINAE = void>
182 : FalseType
183 {};
184
188 template<template<class...> class Predicate>
189 struct IsAlwaysFalse<Predicate, std::enable_if_t<!Predicate<>::value> >
190 : TrueType
191 {};
192
194 template<template<class...> class P0, template<class...> class P1>
196 {
197 template<class... Arg>
198 struct Predicate
199 : BoolConstant<P0<Arg...>::value && P1<Arg...>::value>
200 {};
201 };
202
204 template<template<class...> class P0, template<class...> class P1>
206 {
207 template<class... Arg>
208 struct Predicate
209 : BoolConstant<P0<Arg...>::value || P1<Arg...>::value>
210 {};
211 };
212
216 template<template<class...> class F, class... Rest>
218 {
224 template<class T, class...>
226 : F<T, Rest...>
227 {};
228
229 template<class T, class...>
230 struct FirstOfPair
231 : F<typename T::first_type, Rest...>
232 {};
233
234 template<class T1, class T2, class...>
235 struct BinaryFirstOfPair
236 : F<typename T1::first_type, typename T2::first_type, Rest...>
237 {};
238
239 template<class T, class...>
240 struct SecondOfPair
241 : F<typename T::second_type, Rest...>
242 {};
243
244 template<class T1, class T2, class...>
245 struct BinarySecondOfPair
246 : F<typename T1::second_type, typename T2::second_type, Rest...>
247 {};
248
252 template<class T>
253 struct Unary
254 : F<T, Rest...>
255 {};
256
257 };
258
262 template<template<class...> class F>
264 {
265 template<class... Arg>
266 using Predicate = F<Arg...>;
267
268 template<class... Arg>
269 constexpr bool operator()(Arg&&...) const
270 {
271 return F<Arg...>::value;
272 }
273 };
274
276 template<class T, class SFINAE = void>
278 : FalseType
279 {};
280
281 template<class T>
282 struct IsSequence<T, std::enable_if_t<!IsDecay<T>::value> >
283 : IsSequence<std::decay_t<T> >
284 {};
285
287 template<class T, T... Ints>
288 struct IsSequence<Sequence<T, Ints...> >
289 : TrueType
290 {};
291
293 template<class T, class SFINAE = void>
295 : FalseType
296 {};
297
298 template<class T>
299 struct IsIndexSequence<T, std::enable_if_t<!IsDecay<T>::value> >
300 : IsIndexSequence<std::decay_t<T> >
301 {};
302
304 template<std::size_t... Ints>
306 : TrueType
307 {};
308
310 template<class T>
312 : FalseType
313 {};
314
315 template<class T>
316 struct IsIntegralConstant<T&>
318 {};
319
320 template<class T>
321 struct IsIntegralConstant<T&&>
322 : IsIntegralConstant<std::decay_t<T> >
323 {};
324
326 template<class T, T V>
328 : TrueType
329 {};
330
332 template<class T>
334 : FalseType
335 {};
336
338 template<class T>
339 struct IsBoolConstant<T&>
341 {};
342
344 template<class T>
345 struct IsBoolConstant<T&&>
347 {};
348
350 template<bool V>
352 : TrueType
353 {};
354
356 template<class, class SFINAE = void>
358 : FalseType
359 {};
360
362 template<class T>
363 struct IsDefined<T,
364 std::enable_if_t<(std::is_object<T>::value &&
365 !std::is_pointer<T>::value &&
366 (sizeof(T) >= 0))>
367 > : TrueType
368 {};
369
371 template<class T, class SFINAE = void>
373 : FalseType
374 {};
375
385 template<class T>
386 struct IsTupleLike<T, std::enable_if_t<(std::tuple_size<std::decay_t<T> >::value >= 0)> >
387 : TrueType
388 {};
389
390 template<class T>
391 struct IsTuple
392 : FalseType
393 {};
394
395 template<class... T>
396 struct IsTuple<std::tuple<T...> >
397 : TrueType
398 {};
399
401 template<class T, class SFINAE = void>
402 struct IsArray
403 : FalseType
404 {};
405
407 template<class T>
408 struct IsArray<T, std::enable_if_t<!IsDecay<T>::value> >
409 : IsArray<std::decay_t<T> >
410 {};
411
413 template<class T, std::size_t N>
414 struct IsArray<std::array<T, N> >
415 : TrueType
416 {};
417
419 template<class T, class SFINAE = void>
421 : FalseType
422 {};
423
424 template<class T>
425 struct HasResize<T, std::enable_if_t<!IsDecay<T>::value> >
426 : HasResize<std::decay_t<T> >
427 {};
428
429 template<class T>
430 struct HasResize<T, VoidType<decltype(std::declval<T>().resize(0UL))> >
431 : TrueType
432 {};
433
437 template<class T1, class T2>
439 : std::is_same<std::decay_t<T1>, std::decay_t<T2> >
440 {};
441
443 template<class T, class SFINAE = void>
445 : FalseType
446 {};
447
449 template<class T>
450 struct HasUnaryMinus<T, std::enable_if_t<(sizeof(decltype(-std::declval<T>())) >= 0)> >
451 : TrueType
452 {};
453
462 template<bool C, class T>
463 struct Case
464 : BoolConstant<C>
465 {
466 using Type = T;
467 };
468
472 template<class CaseType>
474
481 template<class A, class B = A>
483
491 template<class A, class B = A>
493
497 template<class A, class B, class C = A>
499
503 template<class A, class B, class C = A>
505
509 template<class A, class B, class C = A>
511
515 template<class A, class B, class C = A>
517
525 template<class Head, class... Tail>
526 struct Switch
527 : ConditionalType<Head::value, Head, Switch<Tail...> >
528 {};
529
534 template<class T>
535 struct Switch<T>
536 {
537 using Type = T;
538 };
539
544 template<bool C, class T>
545 struct Switch<Case<C, T> >
546 {
547 static_assert(C, "Type-switch without terminating \"true\" case.");
548 using Type = T;
549 };
550
563 template<class... Cases>
564 using SwitchType = typename Switch<Cases...>::Type;
565
569 template<bool C, class Yes, class No = void>
571
573 template<class... A>
575
577 template<class A, class B, class Default = void>
579
583 template<class T, class U>
585 {
586 private:
587 using R = std::remove_reference_t<T>;
588 using U0 = std::decay_t<U>; // = U?
589 using U1 = ConditionalType<std::is_const<R>::value, std::add_const_t<U0>, U0>;
590 using U2 = ConditionalType<std::is_volatile<R>::value, std::add_volatile_t<U1>, U1>;
591 using U3 = ConditionalType<std::is_lvalue_reference<T>::value, std::add_lvalue_reference_t<U2>, U2>;
592 using U4 = ConditionalType<std::is_rvalue_reference<T>::value, std::add_rvalue_reference_t<U3>, U3>;
593 public:
594 using type = U4;
595 };
596
598 template<class From, class To>
599 using copy_cv_reference_t = typename copy_cv_reference<From, To>::type;
600
608 template<class T>
610 {
611 using type = ConditionalType<std::is_lvalue_reference_v<T>,
612 std::add_lvalue_reference_t<std::remove_const<std::remove_reference_t<T> > >,
613 std::remove_const<std::remove_reference_t<T> > >;
614 };
615
617 template<class T>
618 using remove_const_t = typename remove_const<T>::type;
619
621 template<class T>
622 constexpr T forwardReturnValue(std::remove_reference_t<T>& t)
623 {
624 return static_cast<T>(t);
625 }
626
630 template<class T>
631 constexpr T forwardReturnValue(std::remove_reference_t<T>&& t)
632 {
633 return static_cast<T&&>(t);
634 }
635
637
639
640 } // ACFem::
641
642} // Dune::
643
644#endif // __DUNE_ACFEM_COMMON_TYPES_HH__
Constant< typename Const::value_type, Const::value+1 > Incr
Increment an integral_constant.
Definition: types.hh:79
Constant< typename Const::value_type, Const::value - 1 > Decr
Decrement an integral_constant.
Definition: types.hh:83
Constant< std::ptrdiff_t, V > IntConstant
Short-for integral constant of type std::p0trdiff_t.
Definition: types.hh:52
Sequence< std::ptrdiff_t, V... > IntSequence
Sequence of std::ptrdiff_t values.
Definition: types.hh:68
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
integral_constant< T, V > Constant
Short-cut for any integral constant.
Definition: types.hh:40
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
Sequence< bool, Decisions... > BoolSequence
Sequence of boolean values.
Definition: types.hh:60
std::is_same< std::decay_t< T1 >, std::decay_t< T2 > > HasSameDecay
true if the decay types match.
Definition: types.hh:98
BoolConstant<(std::is_const< T >::value||std::is_const< std::remove_reference_t< T > >::value)> RefersConst
TrueType if const or a reference to a const.
Definition: types.hh:133
constexpr auto falseType()
Generate a FalseType.
Definition: types.hh:116
constexpr auto boolType(BoolConstant< Cond > arg=BoolConstant< Cond >{})
Generate a BoolConstant.
Definition: types.hh:120
constexpr T forwardReturnValue(std::remove_reference_t< T > &t)
Forward lvalue-references as references.
Definition: types.hh:622
SwitchType< CaseNotVoid< A >... > OrType
First non-void type in list.
Definition: types.hh:574
typename MakeType< T... >::Type FirstType
Generate the first type of the template argument list.
Definition: types.hh:147
typename copy_cv_reference< From, To >::type copy_cv_reference_t
Export a type copy_cv_reference::type which has the same qualifiers as T and decays to the decay of U...
Definition: types.hh:599
typename MakeType< FalseType, Other... >::Type AlwaysFalse
Generate FalseType regardless of the template argument list.
Definition: types.hh:155
typename MakeType< TrueType, Other... >::Type AlwaysTrue
Generate TrueType regardless of the template argument list.
Definition: types.hh:159
constexpr auto forwardAsPair(T0 &&t0, T1 &&t1)
Forward as pair capturing lvalue references.
Definition: types.hh:124
typename MakeType< void, Other... >::Type VoidType
Generate void regardless of the template argument list.
Definition: types.hh:151
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
SwitchType< Case< C, Yes >, No > IfElseType
Type Yes if C is true, otherwise type No which default to void.
Definition: types.hh:570
std::is_same< T, std::decay_t< T > > IsDecay
true if T is its own decay type.
Definition: types.hh:94
typename remove_const< T >::type remove_const_t
Export a type trough remove_const::type as follows:
Definition: types.hh:618
typename Switch< Cases... >::Type SwitchType
Multiple conditions.
Definition: types.hh:564
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
SwitchType< CaseSame< A, B >, Default > AndType
A if A and B have same type, otherwise Default.
Definition: types.hh:578
constexpr auto trueType()
Generate a TrueType.
Definition: types.hh:113
std::is_base_of< std::decay_t< Base >, std::decay_t< Derived > > IsBaseOfDecay
TrueType if the decay type of Base is a base of the DecayType of Derived.
Definition: types.hh:104
STL namespace.
Logical "and" for two perdicates.
Definition: types.hh:196
Case-structure for multi-conditional switch.
Definition: types.hh:465
T Type
export T.
Definition: types.hh:466
Gets the type of the n-th element of a tuple-like or the std::integral_constant corresponding to the ...
Definition: access.hh:42
Definition: types.hh:422
Definition: types.hh:446
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:404
Definition: types.hh:335
Definition: types.hh:359
Definition: types.hh:296
FalseType by default.
Definition: types.hh:313
Definition: types.hh:279
Definition: types.hh:374
Definition: types.hh:141
Logical "or" for two perdicates.
Definition: types.hh:206
Discard any but the first template parameter, instantiate F with T and Rest.
Definition: types.hh:227
Generate a one-parameter template to support template-template arguments with a single argument.
Definition: types.hh:255
Wrap the given predicate class F into another one with spcial requirements.
Definition: types.hh:218
Wrap a predicate into a class which can be passed on as argument.
Definition: types.hh:264
TrueType if T1 and T2 have the same decay types, otherwise FalseType.
Definition: types.hh:440
Recursion for a multi-conditional switch.
Definition: types.hh:528
Export a type copy_cv_reference::type which has the same qualifiers as T and decays to the decay of U...
Definition: types.hh:585
Export a type trough remove_const::type as follows:
Definition: types.hh:610
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)