Created
May 5, 2020 21:01
-
-
Save burritoOverflow/1c4ee5d859eb6412a114bdbf1e0c4bd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <set> | |
#include <vector> | |
#include <iterator> | |
#include <iostream> | |
using namespace std; | |
struct even_compare | |
{ | |
bool operator()(const int &lhs, const int &rhs) const | |
{ | |
if (lhs & 1 && rhs & 1) | |
{ | |
return lhs < rhs; | |
} | |
else if (lhs & 1) | |
{ | |
return false; | |
} | |
else if (rhs & 1) | |
{ | |
return true; | |
} | |
// both are even | |
return lhs < rhs; | |
} | |
}; | |
int main() | |
{ | |
set<int> x{3, 2, 6, 8, 1, 9, 5, 7}; | |
copy(x.begin(), x.end(), ostream_iterator<int>(cout, ", ")); | |
cout << '\n'; | |
vector<int> v{3, 3, 4, 1, 1, 4, 2, 3, 2}; | |
x.insert(v.begin(), v.end()); | |
copy(x.begin(), x.end(), ostream_iterator<int>(cout, ", ")); | |
cout << '\n'; | |
set<int, even_compare> w; | |
// copy contents from x to w | |
copy(x.begin(), x.end(), inserter(w, w.begin())); | |
copy(w.begin(), w.end(), ostream_iterator<int>(cout, ", ")); | |
cout << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment