-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexercise1.cpp
33 lines (30 loc) · 843 Bytes
/
exercise1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "city.h"
#include "country.h"
#include "world-util.h"
#include <set>
#include <map>
#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
#include <numeric>
using namespace std;
using namespace world;
map<int,shared_ptr<city>> cities;
map<string,shared_ptr<country>> countries;
void print_continent(const string& continent){
cout << continent << "\t" ;
}
int main(int argc, char* argv[]){
create_world();
auto continentReducer = [](auto&& conts,auto& entry){
auto country = entry.second;
conts.insert(country->continent);
return conts;
};
// reduce
auto continents = accumulate(countries.begin(),countries.end(),set<string>(),continentReducer);
for_each(continents.begin(),continents.end(),print_continent);
cout << endl << "done." << endl;
return 0;
}