Skip to content

Instantly share code, notes, and snippets.

@sturmer sturmer/allof.cpp
Created Dec 22, 2013

Embed
What would you like to do?
Example of std::all_of
#include <algorithm>
#include <iostream>
#include <vector>
using std::vector;
using std::all_of;
using std::cout;
enum Continent {
EUROPE, ASIA, AMERICA, AFRICA, AUSTRALIA
};
struct Person {
std::string name;
Continent continent;
};
int main(int argc, const char *argv[])
{
Person gianluca{"Gianluca", Continent::EUROPE};
Person simon{"Simon", Continent::EUROPE};
Person xiang{"Xiang", Continent::ASIA};
vector<Person> persons{gianluca, simon, xiang};
bool all_european = all_of(persons.cbegin(),
persons.cend(),
[](const Person& p) { return p.continent == Continent::EUROPE; });
if (all_european)
cout << "All European visitors\n";
else
cout << "Visitors from outside Europe\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.