-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_if.cpp
45 lines (38 loc) · 905 Bytes
/
remove_if.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
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;++i)
struct citizen{
string name;
int age;
};
ostream& operator<<(ostream& os, const citizen& c){
return (os << "[Name: " << c.name << ", Age: " << c.age << "]");
}
int main(){
forward_list<citizen> citizens = {{"Raj", 22}, {"Rohit", 25}, {"Rohan", 17}, {"Sachin", 16}};
auto citizens_copy = citizens;
cout << "All citizens: ";
for(const auto &c : citizens){
cout << c << " ";
}
cout << endl;
citizens.remove_if(
[](const citizen& c){
return (c.age < 18);
}
);
cout << "Eligible citizens for voting: ";
for(const auto& c : citizens)
cout << c << " ";
cout << endl;
citizens_copy.remove_if(
[](const citizen& c){
return (c.age != 17);
}
);
cout << "Citizens that will be eligible for voting next year: ";
for(const auto& c : citizens_copy){
cout << c << " ";
}
cout << endl;
}