DUNE-ACFEM (unstable)

expressiontraits.hh
Go to the documentation of this file.
1 #ifndef __DUNE_ACFEM_EXPRESSIONS_EXPRESSIONTRAITS_HH__
2 #define __DUNE_ACFEM_EXPRESSIONS_EXPRESSIONTRAITS_HH__
3 
9 #include "../common/types.hh"
10 #include "policy.hh"
11 #include "sign.hh"
12 
13 namespace Dune
14 {
15 
16  namespace ACFem
17  {
18 
37  enum TraitsPriority {
38  DefaultTraitsLevel = 0
39  , BaseTraitsLevel
40  , DecayTraitsLevel
41  , TopTraitsLevel = Expressions::Policy::TraitsLevelMax::value
42  , Primary = TopTraitsLevel
43  , Secondary = (int)TopTraitsLevel - 1
44  };
45 
49  template<class T,
50  class SFINAE = void,
51  std::size_t Priority = TopTraitsLevel>
53  : ExpressionTraits<T, void, Priority-1>
54  {};
55 
62  template<class T>
63  struct ExpressionTraits<T, void, DefaultTraitsLevel>
64  : public UnknownExpressionSign
65  {
66  using ExpressionType = void;
67 
68  static constexpr bool isOne = false;
69  static constexpr bool isMinusOne = false;
70 
71  static constexpr bool isVolatile = false;
72  static constexpr bool isIndependent = false;
73  static constexpr bool isConstant = false;
74  static constexpr bool isTypedValue = false;
75  };
76 
81  template<class T>
82  struct ExpressionTraits<T,
83  std::enable_if_t<!IsDecay<T>::value>,
84  DecayTraitsLevel>
85  : public ExpressionTraits<std::decay_t<T> >
86  {};
87 
89  template<class T>
91 
93  template<class T>
95 
97  template<class T>
99  {
100  using ExpressionType = std::decay<T>;
101  static constexpr bool isNonZero = false;
102  static constexpr bool isNonSingular = false;
103  static constexpr bool isZero = true;
104  static constexpr bool isOne = false;
105  static constexpr bool isMinusOne = false;
106  static constexpr bool isSemiPositive = true;
107  static constexpr bool isSemiNegative = true;
108  static constexpr bool isPostive = false;
109  static constexpr bool isNegative = false;
110 
111  static constexpr bool isVolatile = false;
112  static constexpr bool isIndependent = true;
113  static constexpr bool isConstant = true;
114  static constexpr bool isTypedValue = true;
115 
117  };
118 
126  template<class T, class SFINAE = void>
127  struct OwnsExpressionTraits
128  : FalseType
129  {};
130 
131  template<class T>
132  struct OwnsExpressionTraits<
133  T,
134  std::enable_if_t<(std::is_class<std::decay_t<T> >::value &&
135  SameDecay<T, typename ExpressionTraits<T>::ExpressionType>::value)> >
136  : TrueType
137  {};
138 
139  template<class Expression, class Int, Int I>
140  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
141  operator<=(const Expression&, Constant<Int, I>)
142  {
143  return ExpressionTraits<Expression>::isSemiNegative && I >= 0;
144  }
145 
146  template<class Expression, class Int, Int I>
147  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
148  operator>=(const Expression&, Constant<Int, I>)
149  {
150  return ExpressionTraits<Expression>::isSemiPositive && I <= 0;
151  }
152 
153  template<class Expression, class Int, Int I>
154  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
155  operator<(const Expression&, Constant<Int, I>)
156  {
157  return ExpressionTraits<Expression>::isNegative && I >= 0;
158  }
159 
160  template<class Expression, class Int, Int I>
161  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
162  operator>(const Expression&, Constant<Int, I>)
163  {
164  return ExpressionTraits<Expression>::isPositive && I <= 0;
165  }
166 
167  template<class Expression, class Int, Int I>
168  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
169  operator==(const Expression&, Constant<Int, I>)
170  {
171  return ExpressionTraits<Expression>::isZero && I == 0;
172  }
173 
174  template<class Expression, class Int, Int I>
175  constexpr std::enable_if_t<OwnsExpressionTraits<Expression>::value, bool>
176  operator!=(const Expression&, Constant<Int, I>)
177  {
178  return ExpressionTraits<Expression>::isZero && I != 0;
179  }
180 
181  template<class T>
182  constexpr auto expressionTraits()
183  {
184  return ExpressionTraits<T>{};
185  }
186 
187  template<class T>
188  constexpr auto expressionTraits(T&&)
189  {
190  return expressionTraits<T>();
191  }
192 
194 
196 
198 
199  } // ACFem
200 
201 } // Dune
202 
203 #endif // __DUNE_ACFEM_EXPRESSIONS_EXPRESSIONTRAITS_HH__
BoolConstant< std::is_reference< T >::value &&IsTypedValue< T >::value > IsTypedValueReference
Compile-time true if T is a reference to a "typed value".
Definition: expressiontraits.hh:94
BoolConstant< ExpressionTraits< T >::isTypedValue > IsTypedValue
Compile-time true if T is a "typed value", e.g. a std::integral_constant.
Definition: expressiontraits.hh:90
constexpr bool isConstant(Sequence< T, T0, Ts... >)
Definition: compare.hh:285
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Default expression traits definition is a recursion in order to ease disambiguation.
Definition: expressiontraits.hh:54
A class mainting the sign of an expression during operations.
Definition: sign.hh:30
ExpressionTraits for any zero-expression.
Definition: expressiontraits.hh:99
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 26, 22:29, 2024)