/* Lecture code 8.1 * * Set algorithms. Demonstrates set_union, ostream_iterator, * inserter. */ #include #include #include // For ostream_iterator, inserter. #include // copy, set_union using namespace std; const int NUM_INTS = 10; int main() { set evens, odds; for(int i = 0; i < NUM_INTS; ++i) { evens.insert(i * 2); odds.insert(i * 2 + 1); } /* Take the union. */ set result; set_union(evens.begin(), evens.end(), odds.begin(), odds.end(), inserter(result, result.begin())); /* Print to cout. */ copy(result.begin(), result.end(), ostream_iterator(cout, "\n")); return 0; }