Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v{3, 8, 12, 5};
auto n = std::count_if(v.begin(), v.end(), [](int a, int b) { return a > b; });
std::cout << n << '\n';
return 0;
}
- A count_if returns bool
- B count_if calls its predicate with ONE element; a two-parameter lambda (a comparator) cannot be called that way Correct
- C v must be sorted
- D The lambda must return int
Correct Answer: Option B
Write [](int x) { return x > 6; } for a unary predicate.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!