Skip to content

Instantly share code, notes, and snippets.

@mochow13
Last active September 12, 2018 07:52
Show Gist options
  • Save mochow13/2a3c510dfd90832472200d576ae7c69a to your computer and use it in GitHub Desktop.
Save mochow13/2a3c510dfd90832472200d576ae7c69a to your computer and use it in GitHub Desktop.
std::vector<int> collection = {3, 6, 12, 6, 9, 12};
// Are all numbers divisible by 3?
// divby3 should equal 1
bool divby3 = std::all_of(begin(collection), end(collection), [](int x) {
return x % 3 == 0;
});
// Is any number divisible by 2?
// divby2 equals true
bool divby2 = std::any_of(begin(collection), end(collection), [](int x) {
return x % 2 == 0;
});
// Is no number divisible by 6?
// divby6 equals false
bool divby6 = std::none_of(begin(collection), end(collection), [](int x) {
return x % 6 == 0;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment