STD Set
STD Set
std::set is an associative container that contains a sorted set of unique objects of type Key. Sorting is done
using the key comparison function Compare. Search, removal, and insertion operations have logarithmic
complexity. Sets are usually implemented as red-black trees .
Everywhere the standard library uses the Compare requirements, uniqueness is determined by using the
equivalence relation. In imprecise terms, two objects a and b are considered equivalent if neither compares
less than the other: !comp(a, b) && !comp(b, a) .
Template parameters
Member types
Iterators
Capacity
Modifiers
Lookup
Observers
operator==
operator!= (removed in C++20)
operator< (removed in C++20)
lexicographically compares the values in the set
operator<= (removed in C++20)
(function template)
operator> (removed in C++20)
operator>= (removed in C++20)
operator<=> (C++20)
specializes the std::swap algorithm
std::swap(std::set)
(function template)
Erases all elements satisfying specific criteria
erase_if(std::set) (C++20)
(function template)
(since C++17)
Deduction guides
Notes
The member types iterator and const_iterator may be aliases to the same type. This means defining a pair
of function overloads using the two types as parameter types may violate the One Definition Rule. Since
iterator is convertible to const_iterator, a single function with a const_iterator as parameter type will
work instead.
Example
Defect Reports
The following behavior-changing defect reports were applied retroactively to previously published C++
standards.