C++ Library - <set>

A set is an Associative container which contains a sorted set of unique objects of type Key. Each element may occur only once, so duplicates are not allowed.
There are four kind of Associative containers: set, multiset, map and multimap.
The value of the elements in a set cannot be modified once in the container, i.e., the elements are always const. But they can be inserted or removed from the container.
set containers are generally slower than unordered_set containers in accessing individual elements by their key, but they allow the direct iteration on subsets based on their order.
Below is definition of std::set from <set> header file
template < 
    class Key,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<Key>
> class set;

Key − Type of the element contained.
Key may be substituted by any other data type including user-defined type.
Key − Type of the element contained.
Key may be substituted by any other data type including user-defined type.
Following member types can be used as parameters or return type by member functions.
value_type&
const value_type&
std::allocator_traits<Allocator>::pointer
std::allocator_traits<Allocator>::const_pointer
Below is list of all methods from <set> header.
DEFAULT MEMBER FUNCTIONS
Constructs the set container.
Constructs the set container with contents of the range.
Constructs the set container with the copy of other set.
Constructs the set container with the contents of other set using move semantics.
Constructs the set container with contents of the inializer list.
Destructs the set container.
Assigns values to the set container.
Returns the iterator to beginning.
Returns the const iterator to beginning.
Returns the iterator to end.
Returns the const iterator to end.
Returns the reverse iterator to reverse beginning.
Return const reverse iterator to reverse beginning.
Returns the reverse iterator to reverse end.
Returns the const reverse iterator to reverse end.
Returns wheteher the set container is empty.
Returns the number of elements in the set container.
Returns the maximum number of elements that the set container can hold.
Removes all elements from the set container.
Inserts new element in the set container.
Inserts new element in the set, if its unique.
Inserts new element in the set, if its unique, with a hint on the inserting position.
Removes either a single element or a range of elements from the set container.
Exchanges the content of the container by the content of another set container of the same type.
Returns the number of elements with matching value in the set container.
Searches the set container for value and returns an iterator to it if found, else returns an iterator to set::end.
Returns an iterator pointing to the first element in the set container which is not considered to go before value.
Returns an iterator pointing to the first element in the set container which is considered to go after value.
Returns the bounds of a range that includes all the elements in the set container that are equivalent to value.
Returns a copy of the comparison object used by the set container.
Returns a copy of the comparison object used by the set container.
Returns a copy of the allocator object associated with the set container.
 Print
 Add Notes
 Bookmark this page