The std header has a few cool additions that make life easier in C++11:
void f() {
vector<int> v = {1, 2, 3, 4, 5, 60, 70, 80, 90};
auto less_than_10 = [](int x){ return x < 10; };
if (all_of(v.begin(), v.end(), less_than_10)) {
cout << "Yay!";
}
}
Besides all_of, in you can also find any_of and none_of.
Bonus: do you find that initializer list hideous? Just use std::iota, from stl too:
vector<int> v(100, 0);
iota(v.begin(), v.end(), 0);
Inequality symbols are rendered as < and > in your post. I checked with Chrome and Explorer.
ReplyDeleteI meant as & l t ; (without spaces) etc.
ReplyDeleteWell, it's quite ironic that your coment was more successful than my post. Thanks for the heads up, I'll try to fix it as soon as I get a chance!
ReplyDelete