... implementation of a set is identical to that of a multiset, except that a set must have unique keys. Therefore, if an attempt is made to insert a duplicate key into a set, the duplicate is ignored—this is the intended mathematical behavior of a set, so it’s not considered an error. A set supports bidirectional iterators (but not random-access iterators). If the order of the keys is not important, you can use unordered_set (header <unordered_set>) instead. Figure 15.16 demonstrates a set of doubles.

Fig. 15.16 Standard Library set class template.

Alternate View

 1   // Fig. 15.16: fig15_16.cpp
 2   // Standard Library set class template.
 3   #include <iostream> ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.