Created
December 22, 2013 13:03
-
-
Save sturmer/8082362 to your computer and use it in GitHub Desktop.
Example of std::all_of
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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