fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <functional>
  5. #include <ext/functional>
  6. struct Person {
  7. std::string name;
  8. Person(const std::string& n) : name(n) {}
  9. std::string getName() const { return name; }
  10. };
  11.  
  12. int main()
  13. {
  14. std::vector<Person*> vec;
  15. vec.push_back(new Person("Arthur"));
  16. vec.push_back(new Person("Chad"));
  17. vec.push_back(new Person("Chad"));
  18.  
  19. ptrdiff_t num_chads = std::count_if(vec.begin(), vec.end(),
  20. __gnu_cxx::compose1(
  21. std::bind2nd(std::equal_to<std::string>(), "Chad"),
  22. std::mem_fun(&Person::getName)));
  23.  
  24. std::cout << "There are " << num_chads << " chads\n";
  25. delete vec[0]; delete vec[1]; delete vec[2];
  26. }
  27.  
Success #stdin #stdout 0s 2860KB
stdin
Standard input is empty
stdout
There are 2 chads