RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
consistencyCheck.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_UTIL_CONSISTENCY_CHECK_HH
22 #define RFFGEN_UTIL_CONSISTENCY_CHECK_HH
23 
24 #include <type_traits>
25 
26 #include "voider.hh"
27 
28 namespace RFFGen
29 {
33  template < class F , class = void >
35  struct HasD0MemberFunction : std::false_type {};
36 
38  template < class F , class IndexedArg , class = void>
39  struct HasD1MemberFunction : std::false_type {};
40 
42  template < class F , class IndexedArgX , class IndexedArgY , class = void >
43  struct HasD2MemberFunction : std::false_type {};
44 
46  template < class F , class IndexedArgX , class IndexedArgY , class IndexedArgZ , class = void>
47  struct HasD3MemberFunction : std::false_type {};
48 
49 
50  namespace Detail
51  {
52  /* Unevaluated function calls: */
54  template <class F> using check_d0_member_presence_t = decltype(std::declval<F>().d0());
55 
57  template < class F , class IndexedArg ,
58  class Arg = typename IndexedArg::type ,
59  int id = IndexedArg::index >
60  using check_d1_member_presence_t = decltype(std::declval<F>().template d1<id>(std::declval<Arg>()));
61 
63  template < class F , class IndexedArgX , class IndexedArgY ,
64  class ArgX = typename IndexedArgX::type ,
65  class ArgY = typename IndexedArgY::type ,
66  int idx = IndexedArgX::index ,
67  int idy = IndexedArgY::index >
68  using check_d2_member_presence_t = decltype(std::declval<F>().template d2<idx,idy>(std::declval<ArgX>(),std::declval<ArgY>()));
69 
71  template < class F , class IndexedArgX , class IndexedArgY , class IndexedArgZ ,
72  class ArgX = typename IndexedArgX::type ,
73  class ArgY = typename IndexedArgY::type ,
74  class ArgZ = typename IndexedArgZ::type ,
75  int idx = IndexedArgX::index ,
76  int idy = IndexedArgY::index ,
77  int idz = IndexedArgZ::index >
78  using check_d3_member_presence_t = decltype(std::declval<F>().template d3<idx,idy,idz>(std::declval<ArgX>(),std::declval<ArgY>(),std::declval<ArgZ>()));
79 
80 
83  template <bool presence_of_d0 = false, bool presence_of_d1 = false, bool presence_of_d2 = false, bool presence_of_d3 = false>
84  struct ConsistentDerivatives : std::false_type {};
85 
87  template <> struct ConsistentDerivatives<true,true,true,true> : std::true_type {};
88 
90  template <> struct ConsistentDerivatives<true,true,true,false> : std::true_type {};
91 
93  template <> struct ConsistentDerivatives<true,true,false,false> : std::true_type {};
94 
96  template <> struct ConsistentDerivatives<true,false,false,false> : std::true_type {};
97 
98 
100  template <bool presence_of_d0 = false, bool presence_of_d1 = false, bool presence_of_d2 = false, bool presence_of_d3 = false>
101  struct NumberOfDerivatives : std::integral_constant<int,-1> {};
102 
104  template <> struct NumberOfDerivatives<true,true,true,true> : std::integral_constant<int,3> {};
105 
107  template <> struct NumberOfDerivatives<true,true,true,false> : std::integral_constant<int,2> {};
108 
110  template <> struct NumberOfDerivatives<true,true,false,false> : std::integral_constant<int,1> {};
111 
113  template <> struct NumberOfDerivatives<true,false,false,false> : std::integral_constant<int,0> {};
114 
115 
116 // /// Convenient alias that calls all member function checks for a function.
117 // template <int id, template <bool,bool,bool,bool> class ConsistencyCheck, class F, class ArgX, class ArgY>
118 // using FMemberCheck = ConsistencyCheck<HasD0MemberFunction<F>::value,
119 // HasD1MemberFunction<id,F,Arg>::value,
120 // HasD2MemberFunction<F,Arg>::value,
121 // HasD3MemberFunction<F,Arg>::value>;
122  }
123 
125  template <class F>
126  struct HasD0MemberFunction<F,void_t<Detail::check_d0_member_presence_t<F> > >
127  : std::true_type
128  {};
129 
131  template < class F , class IndexedArg >
132  struct HasD1MemberFunction<F,IndexedArg,void_t<Detail::check_d1_member_presence_t<F,IndexedArg> > >
133  : std::true_type
134  {};
135 
137  template < class F , class IndexedArgX , class IndexedArgY >
138  struct HasD2MemberFunction<F,IndexedArgX,IndexedArgY,void_t<Detail::check_d2_member_presence_t<F,IndexedArgX,IndexedArgY> > >
139  : std::true_type
140  {};
141 
143  template <class F, class IndexedArgX, class IndexedArgY, class IndexedArgZ>
144  struct HasD3MemberFunction<F,IndexedArgX,IndexedArgY,IndexedArgZ,void_t<Detail::check_d3_member_presence_t<F,IndexedArgX,IndexedArgY,IndexedArgZ> > >
145  : std::true_type
146  {};
147 
148  template <class F>
149  constexpr bool hasD0MemberFunction() { return HasD0MemberFunction<F>::value; }
150 
151  template < class F , class IndexedArgX >
152  constexpr bool hasD1MemberFunction() { return HasD1MemberFunction<F,IndexedArgX>::value; }
153 
154  template < class F , class IndexedArgX , class IndexedArgY >
155  constexpr bool hasD2MemberFunction() { return HasD2MemberFunction<F,IndexedArgX,IndexedArgY>::value; }
156 
157  template < class F , class IndexedArgX , class IndexedArgY , class IndexedArgZ >
158  constexpr bool hasD3MemberFunction() { return HasD3MemberFunction<F,IndexedArgX,IndexedArgY,IndexedArgZ>::value; }
159 
160  template < class F >
161  constexpr bool hasConsistentFirstDerivative()
162  {
163  return hasD0MemberFunction<F>();
164  }
165 
166  template < class F , class IndexedArgX , class IndexedArgY >
167  constexpr bool hasConsistentSecondDerivative()
168  {
169  return hasConsistentFirstDerivative<F>() &&
170  ( hasD2MemberFunction<F,IndexedArgX,IndexedArgY>() ? hasD1MemberFunction<F,IndexedArgX>() : true );
171  }
172 
173  template < class F, class IndexedArgX , class IndexedArgY , class IndexedArgZ >
174  constexpr bool hasConsistentThirdDerivative()
175  {
176  return hasConsistentSecondDerivative<F,IndexedArgX,IndexedArgY>() &&
177  ( hasD3MemberFunction<F,IndexedArgX,IndexedArgY,IndexedArgZ>() ? hasD2MemberFunction<F,IndexedArgX,IndexedArgY>() : true );
178  }
179 
180 
181 // /// Checks if the derivatives in F are defined consistently.
182 // template <int id, class F, class Arg>
183 // constexpr bool hasConsistentDerivatives()
184 // {
185 // return Detail::FMemberCheck<id,Detail::ConsistentDerivatives,F,Arg>::value;
186 // }
187 
188 
189 // /// Statically compute the number of non-vanishing derivatives defined in F (maximum is 3).
190 // template <int id, class F, class Arg>
191 // constexpr int numberOfDerivatives()
192 // {
193 // return Detail::FMemberCheck<id, Detail::NumberOfDerivatives,F,Arg>::value;
194 // }
198 }
199 
200 #endif // RFFGEN_UTIL_CONSISTENCY_CHECK_HH
typename Detail::voider< Types...>::type void_t
Most fascinating type ever. Is always void.
Definition: voider.hh:40