fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <functional>
  5.  
  6. class IntFinder {
  7. public:
  8. explicit IntFinder(int value): m_value(value) { }
  9. bool check(int value) const { return m_value == value; }
  10. private:
  11. int m_value;
  12. };
  13.  
  14. int main() {
  15. IntFinder f(42);
  16. std::vector<int> vec = { 1, 3, 42, 5, 7 };
  17. auto finder = std::mem_fn(&IntFinder::check);
  18. auto pred = std::bind(finder, f, std::placeholders::_1);
  19. auto v = std::find_if(std::begin(vec), std::end(vec), pred);
  20. std::cout << *v << std::endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
42