21 #ifndef RFFGEN_UTIL_COMPUTE_SUM_HH
22 #define RFFGEN_UTIL_COMPUTE_SUM_HH
33 template <
class X,
class Y,
bool Xpresent,
bool Ypresent>
36 static constexpr
bool present =
false;
37 ComputeSumImpl(
const X&,
const Y&) {}
40 template <
class X,
class Y>
41 struct ComputeSumImpl<X,Y,true,true>
43 static constexpr
bool present =
true;
45 ComputeSumImpl(
const X& x,
const Y& y) : value(x() + y())
48 auto operator()()
const
53 decltype(std::declval<X>()() + std::declval<Y>()()) value;
56 template <class X, class Y>
57 struct ComputeSumImpl<X,Y,true,false>
59 static constexpr
bool present =
true;
61 ComputeSumImpl(
const X& x,
const Y&) : value(x())
64 auto operator()()
const
69 decltype(std::declval<X>()()) value;
72 template <class X, class Y>
73 struct ComputeSumImpl<X,Y,false,true>
75 static constexpr
bool present =
true;
77 ComputeSumImpl(
const X&,
const Y& y) : value(y())
80 auto operator()()
const
85 decltype(std::declval<Y>()()) value;
89 template <class...> struct ComputeSum;
91 template <class X, class Y>
92 struct ComputeSum<X,Y> : public Detail::ComputeSumImpl<X,Y,X::present,Y::present>
94 ComputeSum(
const X& x,
const Y& y)
95 : Detail::ComputeSumImpl<X,Y,X::present,Y::present>(x,y)
98 template <
class F,
class G,
class... Args>
99 ComputeSum(F
const& f, G
const& g,
const Args&... args) : ComputeSum( X(f,args...), Y(g,args...) )
103 template <
class X,
class... Y>
104 struct ComputeSum<X,Y...> :
public ComputeSum<X,ComputeSum<Y...> >
106 ComputeSum(
const X& x,
const Y&... y) : ComputeSum<X,ComputeSum<Y...> >(x,ComputeSum<Y...>(y...))
114 #endif // RFFGEN_UTIL_COMPUTE_SUM_HH