C++ set Library
C++ set Functions
The <set> library has functions that let you add, find and remove elements in a set. A set stores unique values, sorted in ascending order.
Many of the functions return an iterator (a pointer-like object that points to an element). Use *it to get the value that the iterator points to.
| Function | Description |
|---|---|
| begin() | Returns an iterator to the first element of a set |
| clear() | Removes all elements from a set |
| count() | Returns 1 if a value exists in a set, and 0 if it does not |
| emplace() | Adds a new element to a set, built directly inside the set |
| empty() | Checks whether a set is empty or not |
| end() | Returns an iterator to the position after the last element of a set |
| erase() | Removes one or more elements from a set |
| find() | Searches for a value, and returns an iterator to the element |
| insert() | Adds one or more elements to a set |
| lower_bound() | Returns an iterator to the first element that is equal to or greater than a given value |
| rbegin() | Returns a reverse iterator to the last element of a set |
| rend() | Returns a reverse iterator to the position before the first element of a set |
| size() | Returns the number of elements in a set |
| swap() | Swaps the contents of two sets |
| upper_bound() | Returns an iterator to the first element that is greater than a given value |