Example 1 — No even numbers
Confirm that a list holds only odd values.
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 3, 5, 7};
bool none = std::none_of(v.begin(), v.end(), [](int n) { return n % 2 == 0; });
std::cout << (none ? "No even numbers" : "Found an even number") << '\n';
return 0;
} How It Works
- The predicate describes what we do not want: even numbers.
- Every value is odd, so the predicate is false each time.
- No match means
none_of()returnstrue.

