fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4.  
  5. template <typename T> struct MinHeap
  6. {
  7. std::function<bool(T, T)> less;
  8.  
  9. MinHeap(const std::function<bool(T, T)>& cmp) : less(cmp)
  10. {
  11. // ...
  12. }
  13. };
  14.  
  15.  
  16. int main()
  17. {
  18. MinHeap<int> yoba([](int a, int b) { return (a % 2 == 1 && b % 2 == 0) || (a % 2 == b % 2 && a < b); });
  19. std::cout << yoba.less(1, 2) << ' '
  20. << yoba.less(7, 2) << ' '
  21. << yoba.less(6, 2) << ' '
  22. << yoba.less(6, 9) << std::endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1 1 0 0