fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. bool my_func1()
  7. {
  8. return true;
  9. }
  10.  
  11. bool my_func2()
  12. {
  13. return false;
  14. }
  15.  
  16. bool my_func3()
  17. {
  18. return true;
  19. }
  20.  
  21. bool my_func4()
  22. {
  23. return false;
  24. }
  25.  
  26. int main()
  27. {
  28. std::vector<std::function<bool()>> functions = {
  29. my_func1,
  30. my_func2,
  31. my_func3,
  32. my_func4
  33. };
  34.  
  35. unsigned long failure =
  36. std::count_if(functions.begin(), functions.end(),
  37. [](const std::function<bool()>& function) { return !function(); });
  38. std::cout << "There was " << failure << " failures." << std::endl;
  39. return 0;
  40. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
There was 2 failures.