fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template<typename T, typename U>
  5. class BinaryFunctor
  6. {
  7. public:
  8. BinaryFunctor(std::function<U(T,T)> a, std::function<U(T,T)> b): a_(a), b_(b) {}
  9.  
  10. bool operator()(T left, T right)
  11. {
  12. return a_(left, right) < b_(left, right);
  13. }
  14.  
  15. private:
  16. std::function<U(T,T)> a_;
  17. std::function<U(T,T)> b_;
  18. };
  19.  
  20. int plus(int l, int r) { return l + r; }
  21. int minus(int l, int r) { return l - r; }
  22.  
  23. int main(int argc, char* argv[])
  24. {
  25. BinaryFunctor<int, int> f(plus, minus);
  26. std::cout << f(1, 2) << std::endl;
  27.  
  28. std::cin.get();
  29. return 0;
  30. }
Success #stdin #stdout 0s 2936KB
stdin
Standard input is empty
stdout
0