Standard C++ Library Class Reference
for (int j = 0; j < 2; j++)
{
for(i = 0; i < 10; ++i) {
// insert values with a hint
si.insert(si.begin(), i);
}
}
// print out the multiset
cout << si << endl;
// Make another int multiset and an empty multiset
set_type si2, siResult;
for (i = 0; i < 10; i++)
si2.insert(i+5);
cout << si2 << endl;
// Try a couple of set algorithms
set_union(si.begin(),si.end(),si2.begin(),si2.end(),
inserter(siResult,siResult.begin()));
cout << "Union:" << endl << siResult << endl;
siResult.erase(siResult.begin(),siResult.end());
set_intersection(si.begin(),si.end(),
si2.begin(),si2.end(),
inserter(siResult,siResult.begin()));
cout << "Intersection:" << endl << siResult << endl;
return 0;
}
Output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
5 6 7 8 9 10 11 12 13 14
Union:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 11 12 13 14
Intersection:
5 6 7 8 9
Warnings
Member function templates are used in all containers provided by the Standard Template Library. An
example of this feature is the constructor for multiset<Key, Compare, Allocator>, which takes two
templated iterators:
template <class InputIterator>
multiset (InputIterator, InputIterator,
const Compare& = Compare(),
const Allocator& = Allocator());
multiset also has an insert function of this type. These functions, when not restricted by compiler
limitations, allow you to use any type of input iterator as arguments. For compilers that do not
support this feature, we provide substitute functions that allow you to use an iterator obtained from