Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:27

0001 #ifndef PhysicsTools_Utilities_Function_h
0002 #define PhysicsTools_Utilities_Function_h
0003 #include "PhysicsTools/Utilities/interface/Variables.h"
0004 #include "PhysicsTools/Utilities/interface/Expression.h"
0005 
0006 namespace funct {
0007 
0008   struct null_var;
0009 
0010   template <typename X1 = null_var, typename X2 = null_var, typename X3 = null_var>
0011   struct Function {
0012     template <typename F>
0013     Function(const F& f) : _f(f) {}
0014     double operator()(typename X1::type x1, typename X2::type x2, typename X3::type x3) const {
0015       X1::set(x1);
0016       X2::set(x2);
0017       X3::set(x3);
0018       return _f();
0019     }
0020     std::ostream& print(std::ostream& cout) const { return _f.print(cout); }
0021 
0022   private:
0023     Expression _f;
0024   };
0025 
0026   template <typename X1, typename X2>
0027   struct Function<X1, X2, null_var> {
0028     template <typename F>
0029     Function(const F& f) : _f(f) {}
0030     double operator()(typename X1::type x1, typename X2::type x2) const {
0031       X1::set(x1);
0032       X2::set(x2);
0033       return _f();
0034     }
0035     std::ostream& print(std::ostream& cout) const { return _f.print(cout); }
0036 
0037   private:
0038     Expression _f;
0039   };
0040 
0041   template <typename X1>
0042   struct Function<X1, null_var, null_var> {
0043     template <typename F>
0044     Function(const F& f) : _f(f) {}
0045     double operator()(typename X1::type x1) const {
0046       X1::set(x1);
0047       return _f();
0048     }
0049     std::ostream& print(std::ostream& cout) const { return _f.print(cout); }
0050 
0051   private:
0052     Expression _f;
0053   };
0054 
0055   template <typename X1, typename X2, typename X3>
0056   std::ostream& operator<<(std::ostream& cout, const Function<X1, X2, X3>& f) {
0057     return f.print(cout);
0058   }
0059 
0060 }  // namespace funct
0061 
0062 #endif