RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
derivativeWrappers.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_DERIVATIVE_WRAPPERS_HH
22 #define RFFGEN_UTIL_DERIVATIVE_WRAPPERS_HH
23 
24 #include <type_traits>
25 #include <utility>
26 
27 #include "consistencyCheck.hh"
28 
29 namespace RFFGen
30 {
34  namespace Detail
35  {
37  template <class F, class IndexedArg, bool IsPresent,
38  class Arg = typename IndexedArg::type,
39  int id = IndexedArg::index>
40  struct D1Impl
41  {
42  static constexpr bool present = false;
43  D1Impl() = delete;
44  D1Impl(F const&, const Arg&){}
45  D1Impl(const D1Impl&) = delete;
46  D1Impl& operator=(const D1Impl&) = delete;
47  };
48 
50  template <class F, class IndexedArg, class Arg, int id>
51  struct D1Impl<F,IndexedArg,true,Arg,id>
52  {
53  static constexpr bool present = true;
54 
55  D1Impl() = delete;
56 
57  D1Impl(const F& f, const Arg& dx) : value(f.template d1<id>(dx)) {}
58 
59  auto operator()() const -> decltype(std::declval<F>().template d1<id>(std::declval<Arg>()))
60  {
61  return value;
62  }
63 
64  D1Impl(const D1Impl&) = delete;
65  D1Impl& operator=(const D1Impl&) = delete;
66 
67  private:
68  decltype(std::declval<F>().template d1<id>(std::declval<Arg>())) value;
69  };
70 
71 
73  template < class F , class IndexedArgX , class IndexedArgY , bool IsPresent ,
74  class ArgX = typename IndexedArgX::type ,
75  class ArgY = typename IndexedArgY::type ,
76  int idx = IndexedArgX::index ,
77  int idy = IndexedArgY::index >
78  struct D2Impl
79  {
80  static constexpr bool present = false;
81  D2Impl() = delete;
82  D2Impl(const F&, const ArgX&, const ArgY&){}
83  D2Impl(const D2Impl&) = delete;
84  D2Impl& operator=(const D2Impl&) = delete;
85  };
86 
88  template < class F , class IndexedArgX , class IndexedArgY , class ArgX , class ArgY , int idx , int idy >
89  struct D2Impl<F,IndexedArgX,IndexedArgY,true,ArgX,ArgY,idx,idy>
90  {
91  static constexpr bool present = true;
92 
93  D2Impl() = delete;
94 
95  D2Impl(const F& f, const ArgX& dx, const ArgY& dy) : value(f.template d2<idx,idy>(dx,dy)) {}
96 
97  auto operator()() const -> decltype(std::declval<F>().template d2<idx,idy>(std::declval<ArgX>(),std::declval<ArgY>()))
98  {
99  return value;
100  }
101 
102  D2Impl(const D2Impl&) = delete;
103  D2Impl& operator=(const D2Impl&) = delete;
104 
105  private:
106  decltype(std::declval<F>().template d2<idx,idy>(std::declval<ArgX>(),std::declval<ArgY>())) value;
107  };
108 
109 
111  template < class F , class IndexedArgX , class IndexedArgY , class IndexedArgZ , bool IsPresent ,
112  class ArgX = typename IndexedArgX::type ,
113  class ArgY = typename IndexedArgY::type ,
114  class ArgZ = typename IndexedArgZ::type ,
115  int idx = IndexedArgX::index ,
116  int idy = IndexedArgY::index ,
117  int idz = IndexedArgZ::index >
118  struct D3Impl
119  {
120  static constexpr bool present = false;
121  D3Impl() = delete;
122  D3Impl(const F&, const ArgX&, const ArgY&, const ArgZ&){}
123  D3Impl(const D3Impl&) = delete;
124  D3Impl& operator=(const D3Impl&) = delete;
125  };
126 
128  template <class F, class IndexedArgX, class IndexedArgY, class IndexedArgZ, class ArgX, class ArgY, class ArgZ, int idx, int idy, int idz>
129  struct D3Impl<F,IndexedArgX,IndexedArgY,IndexedArgZ,true,ArgX,ArgY,ArgZ,idx,idy,idz>
130  {
131  static constexpr bool present = true;
132 
133  D3Impl() = delete;
134 
135  D3Impl(const F& f, const ArgX& dx, const ArgY& dy, const ArgZ& dz) : value(f.template d3<idx,idy,idz>(dx,dy,dz)) {}
136 
137  auto operator()() const -> decltype(std::declval<F>().template d3<idx,idy,idz>(std::declval<ArgX>(),std::declval<ArgY>(),std::declval<ArgZ>()))
138  {
139  return value;
140  }
141 
142  D3Impl(const D3Impl&) = delete;
143  D3Impl& operator=(const D3Impl&) = delete;
144 
145  private:
146  decltype(std::declval<F>().template d3<idx,idy,idz>(std::declval<ArgX>(),std::declval<ArgY>(),std::declval<ArgZ>())) value;
147  };
148  }
149 
151  template <class F>
152  struct D0
153  {
154  static constexpr bool present = HasD0MemberFunction<F>();
155 
156  D0() = delete;
157 
158  D0(const F& f) : value(f.d0()) {}
159 
160  auto operator()() const ->decltype(std::declval<F>().d0())
161  {
162  return value;
163  }
164 
165  D0(const D0&) = delete;
166  D0& operator=(const D0&) = delete;
167 
168  private:
169  decltype(std::declval<F>().d0()) value;
170  };
171 
173  template < class F, class IndexedArg >
174  using D1 = Detail::D1Impl<F,IndexedArg,HasD1MemberFunction<F,IndexedArg>::value>;
175 
177  template < class F , class IndexedArgX , class IndexedArgY >
178  using D2 = Detail::D2Impl<F,IndexedArgX,IndexedArgY,HasD2MemberFunction<F,IndexedArgX,IndexedArgY>::value>;
179 
181  template < class F , class IndexedArgX , class IndexedArgY , class IndexedArgZ >
182  using D3 = Detail::D3Impl<F,IndexedArgX,IndexedArgY,IndexedArgZ,HasD3MemberFunction<F,IndexedArgX,IndexedArgY,IndexedArgZ>::value>;
186 }
187 
188 #endif // RFFGEN_UTIL_DERIVATIVE_WRAPPERS_HH