DUNE-ACFEM (unstable)

terminal.hh
1#ifndef __DUNE_ACFEM_EXPRESSIONS_TERMINAL_HH__
2#define __DUNE_ACFEM_EXPRESSIONS_TERMINAL_HH__
3
4#include "../common/types.hh"
5
6#include "storage.hh"
7#include "interface.hh"
8#include "tags.hh"
9#include "operationtraits.hh"
10
11namespace Dune
12{
13
14 namespace ACFem
15 {
16
17 namespace Expressions
18 {
22 template<class T>
25 {
27 using FunctorType = OperationTraits<OperationType>;
28 template<std::size_t I>
29 using OperandType = ConditionalType<I == 0, T, void>;
30
31 static constexpr auto operation()
32 {
33 return FunctorType{};
34 }
35
36 static constexpr std::size_t arity()
37 {
38 return 1;
39 }
40
41 template<std::size_t I>
42 decltype(auto) operand(IndexConstant<I> = IndexConstant<I>{})
43 {
44 static_assert(I < arity(), "Not so many operands");
45 return static_cast<T&>(*this);
46 }
47
48 template<std::size_t I>
49 decltype(auto) operand(IndexConstant<I> = IndexConstant<I>{}) const
50 {
51 static_assert(I < arity(), "Not so many operands");
52 return static_cast<const T&>(*this);
53 }
54 };
55
57 template<class T, class SFINAE = void>
59 : BoolConstant<std::is_same<T, Operand<0, T> >::value>
60 {};
61
62 template<class T>
63 struct IsSelfExpression<T, std::enable_if_t<IsDecay<T>::value && !IsExpression<T>::value> >
64 : FalseType
65 {};
66
67 template<class T>
68 struct IsSelfExpression<T, std::enable_if_t<!IsDecay<T>::value> >
69 : IsSelfExpression<std::decay_t<T> >
70 {};
71
72 template<class T>
73 using IsTerminal = BoolConstant<(IsSelfExpression<T>::value
74 || HasTag<T, TerminalExpression>::value)>;
75
77 template<class T, class SFINAE = void>
78 struct IsOperand
79 : FalseType
80 {};
81
83 template<class T>
84 struct IsOperand<T, std::enable_if_t<!IsDecay<T>::value> >
85 : IsOperand<std::decay_t<T> >
86 {};
87
89 template<class T>
90 struct IsOperand<T, std::enable_if_t<(IsExpression<T>::value && IsDecay<T>::value)> >
91 : TrueType
92 {};
93
97 template<class T, class SFINAE = void>
99
100 template<
101 class T,
102 std::enable_if_t<(IsOperand<T>::value
103 && !IsExpression<T>::value
104 ), int> = 0>
105 auto asExpression(T&& t)
106 {
107 return InjectionTraits<T>::asExpression(std::forward<T>(t));
108 }
109
110 } // Expressions
111
113
114 template<class T>
116
117 } // ACFem
118
119} // Dune
120
121#endif // __DUNE_ACFEM_EXPRESSIONS_TERMINAL_HH__
constexpr decltype(auto) asExpression(T &&t)
Return a non-closure expression as is.
Definition: interface.hh:122
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
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
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
STL namespace.
Traits class in order to inject general object into the expression chain in a controlled manner.
Definition: terminal.hh:98
Definition: terminal.hh:80
Identify self-contained terminals, see SelfExpression.
Definition: terminal.hh:60
Terminals may derive from this class to express that they are expressions.
Definition: terminal.hh:25
Identity, i.e. just wrap the object.
Definition: expressionoperations.hh:95
A terminal expression is an "expression end-point", i.e.
Definition: tags.hh:48
Tag structures defining properties of expressions.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)