DUNE-ACFEM (unstable)

interface.hh
1#ifndef __DUNE_ACFEM_EXPRESSIONS_INTERFACE_HH__
2#define __DUNE_ACFEM_EXPRESSIONS_INTERFACE_HH__
3
4#include "../common/literals.hh"
5#include "../common/typetraits.hh"
6#include "expressiontraits.hh"
7#include "storage.hh"
8#include "optimizationbase.hh"
9
10namespace Dune
11{
12
13 namespace ACFem
14 {
15
16 namespace Expressions
17 {
18
47 template<class T, class SFINAE = void>
48 struct IsClosure
49 : FalseType
50 {};
51
53 template<class T>
54 struct IsClosure<T, std::enable_if_t<!IsDecay<T>::value> >
55 : IsClosure<std::decay_t<T> >
56 {};
57
59 template<class T, class SFINAE = void>
61 {
62 using ExpressionType = T;
63 };
64
66 template<class T>
67 struct ClosureTraits<T, std::enable_if_t<IsClosure<T>::value> >
68 {
69 using ExpressionType = Operand<0, T>;
70 };
71
76 template<class T>
77 using EnclosedType = typename ClosureTraits<T>::ExpressionType;
78
79 template<class T>
81
87 template<
88 class T,
89 std::enable_if_t<(Expressions::IsClosure<T>::value
90 || (!IsExpression<T>::value
92 ), int> = 0>
93 constexpr decltype(auto) expressionClosure(T&& t)
94 {
95 return std::forward<T>(t);
96 }
97
98 struct Closure
99 {
100 template<class T>
101 constexpr decltype(auto) operator()(T&& t) const
102 {
103 return expressionClosure(std::forward<T>(t));
104 }
105 };
106
107 struct Disclosure
108 {
109 template<class T>
110 constexpr decltype(auto) operator()(T&& t) const
111 {
112 return std::forward<T>(t);
113 }
114 };
115
117 template<
118 class T,
119 std::enable_if_t<(IsExpression<T>::value
120 && !IsClosure<T>::value
121 ), int> = 0>
122 constexpr decltype(auto) asExpression(T&& t)
123 {
124 return std::forward<T>(t);
125 }
126
128 template<
129 class T,
130 std::enable_if_t<(IsExpression<T>::value
131 && IsClosure<T>::value
132 ), int> = 0>
133 constexpr decltype(auto) asExpression(T&& t)
134 {
135 using namespace Literals;
136 danglingReferenceCheck<0>(std::forward<T>(t));
137 return std::forward<T>(t).operand(0_c);
138 }
139
140 template<class T>
141 using IsPromotedTopLevel = BoolConstant<IsClosure<T>::value || IsTypedValueReference<T>::value || IsIntegralConstant<T>::value>;
142
152 template<std::size_t N, class... T,
153 std::enable_if_t<(NthIs<N, IsClosure, T...>::value && !AnyIs<IsIntegralConstant, T...>::value), int> = 0>
154 constexpr decltype(auto) operandPromotion(T&&... t)
155 {
156 return asExpression(get<N>(std::forward_as_tuple(std::forward<T>(t)...)));
157 }
158
160 template<std::size_t N, class... T,
161 std::enable_if_t<(!NthIs<N, IsClosure, T...>::value
162 && NthIs<N, IsTypedValueReference, T...>::value
163 && !AnyIs<IsIntegralConstant, T...>::value
164 ), int> = 0>
165 constexpr auto operandPromotion(T&&... t)
166 {
167 return std::decay_t<TupleElement<N, std::tuple<T...> > >(get<N>(std::forward_as_tuple(std::forward<T>(t)...)));
168 }
169
170 template<std::size_t N, class... T,
171 std::enable_if_t<(AnyIs<IsPromotedTopLevel, T...>::value
172 && !NthIs<N, IsPromotedTopLevel, T...>::value
173 ), int> = 0>
174 constexpr decltype(auto) operandPromotion(T&&... t)
175 {
176 return std::forward<TupleElement<N, std::tuple<T...> > >(get<N>(std::forward_as_tuple(std::forward<T>(t)...)));
177 }
178
180
182
183 } // Expressions
184
186
187 } // ACFem
188
189} // Dune
190
191#endif // __DUNE_ACFEM_EXPRESSIONS_INTERFACE_HH__
constexpr decltype(auto) asExpression(T &&t)
Return a non-closure expression as is.
Definition: interface.hh:122
typename ClosureTraits< T >::ExpressionType EnclosedType
Type alias shortcut to get hold of the type contained in an "expression closure".
Definition: interface.hh:77
constexpr decltype(auto) operandPromotion(T &&... t)
The purpose of this function is to promote operands to other types, e.g.
Definition: interface.hh:154
constexpr decltype(auto) expressionClosure(T &&t)
Do-nothing default implementation for pathologic cases.
Definition: interface.hh:93
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
std::tuple_element_t< N, std::decay_t< TupleLike > > TupleElement
Forward to std::tuple_element<N, std::decay_t<T> >
Definition: access.hh:125
Predicate< TypePackElement< N, T... > > NthIs
Instantiates to Predicate applied to the N-th element of T...
Definition: compare.hh:470
BoolConstant<(...||Predicate< T >::value)> AnyIs
TrueType if any type matches the predicate.
Definition: compare.hh:462
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
typename RemoveRValueReference< T >::Type RemoveRValueReferenceType
If T is an rvalue reference then yield the dereferenced type.
Definition: removervaluereference.hh:38
STL namespace.
Provide the type ExpressionType for non-closure expressions.
Definition: interface.hh:61
An expression closure is a wrapper class which wraps an expression in order to interface to other exi...
Definition: interface.hh:50
FalseType by default.
Definition: types.hh:313
std::true_type if F is an "elementary" scalar.
Definition: typetraits.hh:35
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)