set


A container that is optimized for fast associative lookup. Items are matched using their operator== . When an item is inserted into a set , the item is stored in a data structure where it can be found quickly. Within the data structure, the items are ordered according to a user-defined comparator function object. A typical user-supplied function object is less , which orders the items in ascending order. Unlike a multiset , a set cannot contain multiple copies of the same item.

Library

Standards<ToolKit>

Declaration


#include <set>

template< class T, class Compare, class Allocator >
class set

Interface

Constructor
set()
Constructs an empty set that orders elements using the comparator Compare() and using Allocator() to manage storage.
Constructor
explicit set( const Compare& comp , const Allocator& alloc )
Constructs an empty set that orders elements using comp and uses alloc (default Allocator() ) to manage storage.
Constructor
set( const T* first , const T* last , const Compare& compare , const Allocator& alloc )
Constructs a set that contains copies of the elements in the range [ first , last ) , using compare (default Compare() ) to order elements and using alloc (default Allocator() ) to manage storage.
Constructor
set( const_iterator first , const_iterator last , const Compare& compare , const Allocator& alloc )
Constructs a set that contains copies of elements in the range [ first , last ) , using compare (default Compare() ) to order elements and using alloc (default Allocator() ) to manage storage.
Constructor
set( const set< T, Compare, Allocator >& other )
Constructs a set that is a copy of other .
Destructor
~set()
Destroys the set and erases all of its items.
=
set< T, Compare, Allocator >& operator=( const set< T, Compare, Allocator >& other )
Replaces the set's contents with a copy of other 's.
begin
iterator begin()
Returns an iterator positioned at the first element in the set.
begin
const_iterator begin() const
Returns a constant iterator positioned at the first element in the set.
clear
void clear()
Erases all of the set elements.
count
size_type count( const T& value ) const
Returns the number of elements in the set that match value .
empty
bool empty() const
Returns true if the set contains no elements.
end
iterator end()
Returns an iterator positioned immediately after the last item in the set.
end
const_iterator end() const
Returns a constant iterator positioned immediately after the last item in the set.
equal_range
pair< iterator, iterator > equal_range( const T& key )
Returns a pair with a first element that is equal to lower_bound() and a second element that is equal to upper_bound() .
equal_range
pair< const_iterator, const_iterator > equal_range( const T& key ) const
Returns a pair with a first element that is equal to lower_bound() and a second element that is equal to upper_bound() .
erase
void erase( iterator pos )
Erases the element at pos .
erase
void erase( iterator first , iterator last )
Erases elements in the range [ first , last ) .
erase
size_type erase( const T& value )
Erases all elements that match value and returns the number of elements erased.
find
iterator find( const T& value )
If the set contains an element that matches value , returns an iterator positioned at the matching element. Otherwise, returns an iterator positioned at end() .
find
const_iterator find( const T& value ) const
If the set contains an element that matches value , returns a constant iterator positioned at the matching element. Otherwise, returns a constant iterator positioned at end() .
get_allocator
Allocator get_allocator() const
Returns a copy of the allocator the set is using to manage storage.
insert
pair< iterator, bool > insert( const T& value )
If the set does not contain an element that matches value , inserts a copy of value and returns a pair with a first element that is an iterator positioned at the new element and with a second element that is true . If the set already contains an element that matches value , returns a pair with a first element that is an iterator positioned at the existing element and with a second element that is false .
insert
iterator insert( iterator pos , const T& value )
Inserts a copy of value if the set does not a contain an element that matches value , using pos as a hint on where to start searching for the correct place to insert.
insert
void insert( const T* first , const T* last )
Inserts copies of elements in the range [ first , last ) .
insert
void insert( const_iterator first , const_iterator last )
Inserts copies of elements in the range [ first , last ) .
key_comp
key_compare key_comp() const
Returns the set's key comparison object.
lower_bound
iterator lower_bound( const T& value )
Returns an iterator positioned at the first location value can be inserted without violating the ordering criteria. If no such location is found, returns an iterator positioned at end() .
lower_bound
const iterator lower_bound( const T& value ) const
Returns a constant iterator positioned at the first location value can be inserted without violating the ordering criteria. If no such location is found, returns a constant iterator positioned at end() .
max_size
size_type max_size() const
Returns the maximum number of entries the set can contain.
rbegin
reverse_iterator rbegin()
Returns a reverse iterator positioned at the last item in the set.
rbegin
const_reverse_iterator rbegin() const
Returns a constant reverse iterator positioned at the last item in the set.
rend
reverse_iterator rend()
Returns a reverse iterator positioned immediately before the first item in the set.
rend
const_reverse_iterator rend() const
Returns a constant reverse iterator positioned immediately before the last item in the set.
size
size_type size() const
Returns the number of entries the set contains.
swap
void swap( hash_set< T, Hash, Equal, Allocator >& other )
Exchanges the contents of set and other .
upper_bound
iterator upper_bound( const T& value )
Returns an iterator positioned at the last location that does not satisfy Compare( element , value ) . If no such location is found, returns an iterator positioned at end() .
upper_bound
const_iterator upper_bound( const T& value ) const
Returns a constant iterator positioned at the last location that does not satisfy Compare( element , value ) . If no such location is found, returns a constant iterator positioned at end() .
value_comp
value_compare value_comp() const
Returns the set's value comparison object.

Non-Member Functions

==
bool operator==( const set< T, Compare, Allocator >& x , const set< T, Compare, Allocator >& y )
Returns true if x contains the same items in the same order as y .
<
bool operator<( const set< T, Compare, Allocator >& x , const set< T, Compare, Allocator >& y )
Returns true if x is lexicographically less than y .
swap
void swap( set< T, Compare, Allocator >& x , set< T, Compare, Allocator >& y )
Exchanges the contents of x and y .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.