Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created October 26, 2011 06:15
Show Gist options
  • Save hidsh/10f41440929dbf5b8b93 to your computer and use it in GitHub Desktop.
Save hidsh/10f41440929dbf5b8b93 to your computer and use it in GitHub Desktop.
test for set and merge using STL
set<int> i1, i2, i3;
int max = 10000;
for(int i=1; i<max; i++) {
i1.insert(i*5);
i2.insert(i*10);
}
// set_union
cout << "set_union --------" << endl;
std::set_union(i1.begin(), i1.end(),
i2.begin(), i2.end(),
insert_iterator<set<int> >(i3, i3.begin() ));
// caution: the following is not permitted because to try to write to readonly field.
// std::set_union(i1.begin(), i1.end(), i2.begin(), i2.end(), i3.begin() );
// ^^^^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment