RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
chainer.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_CHAINER_HH
22 #define RFFGEN_UTIL_CHAINER_HH
23 
24 #include <type_traits>
25 #include "base.hh"
26 #include "../MathematicalOperations/chain.hh"
27 
28 namespace RFFGen
29 {
33  template <class Function>
34  struct Chainer
35  {
36  decltype(auto) operator()() const noexcept
37  {
38  return static_cast<const Function*>(this)->d0();
39  }
40 
41  template < class Arg ,
42  class = std::enable_if_t< !std::is_base_of<Base,Arg>::value > >
43  decltype(auto) operator()(const Arg& x)
44  {
45  static_cast<Function*>(this)->update(x);
46  return static_cast<const Function*>(this)->d0();
47  }
48 
49  template < class OtherFunction ,
50  class = std::enable_if_t< std::is_base_of<Base,OtherFunction>::value > >
51  auto operator()(const OtherFunction& g)
52  {
53  return MathematicalOperations::Chain<Function,OtherFunction>(*static_cast<const Function*>(this),g);
54  }
55  };
59 }
60 #endif // RFFGEN_UTIL_CHAINER_HH