Standard C++ Library User Guide and Tutorial
Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
The set Data Abstraction
Sets, Ordered and Not
A set is a collection of values. Because the container used to implement the set data structure
maintains values in an ordered representation, sets are optimized for insertion and removal of
elements, and for testing to see whether a particular value is contained in the collection. Each of
these operations can be performed in a logarithmic number of steps, whereas for a list, vector,
or deque, each operation requires in the worst case an examination of every element held by the
container. For this reason, sets should be the data structure of choice in any problem that
emphasizes insertion, removal, and test for inclusion of values. Like a list, a set is not limited in
size, but rather expands and contracts as elements are added to or removed from the collection.
There are two varieties of sets provided by the standard library. In the set container, every
element is unique. Insertions of values that are already contained in the set are ignored. In the
multiset container, on the other hand, multiple occurrences of the same value are permitted.
Include Files
Whenever you use a set or a multiset, you must include the set header file.
# include <set>