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