RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
computeProduct.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_COMPUTE_PRODUCT_HH
22 #define RFFGEN_UTIL_COMPUTE_PRODUCT_HH
23 
24 #include <utility>
25 
26 namespace RFFGen
27 {
31  namespace Detail
32  {
33  template <class X, class Y, bool bothPresent>
34  struct ComputeProductImpl
35  {
36  static constexpr bool present = false;
37  ComputeProductImpl(X const&, Y const&) {}
38  };
39 
40  template <class X, class Y>
41  struct ComputeProductImpl<X,Y,true>
42  {
43  static constexpr bool present = true;
44 
45  ComputeProductImpl(X const& x, Y const& y) : value( x() * y() )
46  {}
47 
48  auto operator()() const
49  {
50  return value;
51  }
52 
53  decltype(std::declval<X>()() * std::declval<Y>()()) value;
54  };
55  }
56  template <class X, class Y>
57  struct ComputeProduct : public Detail::ComputeProductImpl<X,Y,X::present && Y::present>
58  {
59  ComputeProduct(X const& x, Y const& y)
60  : Detail::ComputeProductImpl<X,Y,X::present && Y::present> (x,y)
61  {}
62 
63 // template <class F, class G, class... Args>
64 // ComputeProduct(F const& f, G const& g, const Args&... args) : ComputeProduct( X(f,args...), Y(g,args...) )
65 // {}
66  };
71 }
72 
73 #endif // RFFGEN_UTIL_COMPUTE_PRODUCT_HH