<set>namespace std {
template<class Key, class Pred, class A>
class set;
template<class Key, class Pred, class A>
class multiset;
// TEMPLATE FUNCTIONS
template<class Key, class Pred, class A>
bool operator==(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator==(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator!=(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator!=(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<=(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<=(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>=(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>=(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
void swap(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
void swap(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
};
Include the STL
standard header <set> to define the container template classes set
and multiset, and their supporting templates.
multisetallocator_type ·
begin
· clear
· const_iterator ·
const_reference
· const_reverse_iterator
· count
· difference_type
· empty
· end
· equal_range
· erase
· find
· get_allocator
· insert
· iterator
· key_comp
· key_compare
· key_type
· lower_bound
· max_size
· multiset
· rbegin
· reference
· rend
· reverse_iterator
· size
· size_type
· swap
· upper_bound
· value_comp
· value_compare
· value_type
template<class Key, class Pred = less<Key>,
class A = allocator<T> >
class multiset {
public:
typedef Key key_type;
typedef Pred key_compare;
typedef Key value_type;
typedef Pred value_compare;
typedef A allocator_type;
typedef typename A::size_type size_type;
typedef typename A::difference_type difference_type;
typedef typename A::rebind<value_type>::other::const_reference
reference;
typedef typename A::rebind<value_type>::other::const_reference
const_reference;
typedef T0 iterator;
typedef T1 const_iterator;
typedef reverse_iterator<const_iterator>
const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
multiset();
explicit multiset(const Pred& comp);
multiset(const Pred& comp, const A& al);
multiset(const multiset& x);
template<class InIt>
multiset(InIt first, InIt last);
template<class InIt>
multiset(InIt first, InIt last,
const Pred& comp);
template<class InIt>
multiset(InIt first, InIt last,
const Pred& comp, const A& al);
const_iterator begin() const;
iterator end() const;
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
size_type size() const;
size_type max_size() const;
bool empty() const;
A get_allocator() const;
iterator insert(const value_type& x);
iterator insert(iterator it, const value_type& x);
template<class InIt>
void insert(InIt first, InIt last);
iterator erase(iterator it);
iterator erase(iterator first, iterator last);
size_type erase(const Key& key);
void clear();
void swap(multiset x);
key_compare key_comp() const;
value_compare value_comp() const;
const_iterator find(const Key& key) const;
size_type count(const Key& key) const;
const_iterator lower_bound(const Key& key) const;
const_iterator upper_bound(const Key& key) const;
pair<const_iterator, const_iterator>
equal_range(const Key& key) const;
protected:
A allocator;
};
The template class describes an object that controls a
varying-length sequence of elements of type const Key.
Each element serves as both a sort key and a value.
The sequence is represented in a way that permits lookup,
insertion, and removal of an arbitrary element with a number of
operations proportional to the logarithm of the number of
elements in the sequence (logarithmic time). Moreover, inserting
an element invalidates no iterators, and removing an element
invalidates only those iterators which point at the removed
element.
The object orders the sequence it controls by calling a stored
function object of type Pred. You access this
stored object by calling the member function key_comp().
Such a function object must impose a total order on sort keys.
For any element x that precedes y in
the sequence, key_comp()(y, x) is false. (For the
default function object less<Key>,
sort keys never decrease in value.) Unlike template class set, an object
of template class multiset does not ensure that key_comp()(x,
y) is true. (Keys need not be unique.)
The object allocates and frees storage for the sequence it
controls through a protected object named allocator, of class
A. Such an allocator
object must have the same external interface as an object of
template class allocator.
Note that allocator is not copied when the
object is assigned.
multiset::allocator_typeyypedef A allocator_type;
The type is a synonym for the template parameter A.
multiset::beginconst_iterator begin() const;
The member function returns a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
multiset::clearvoid clear();
The member function calls erase( begin(), end()).
multiset::const_iteratortypedef T1 const_iterator;
The type describes an object that can serve as a constant
bidirectional iterator for the controlled sequence. It is
described here as a synonym for the unspecified type T1.
multiset::const_referencetypedef typename A::rebind<value_type>::other::const_reference
const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
multiset::const_reverse_iteratortypedef reverse_iterator<const_iterator>
const_reverse_iterator;
The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.
multiset::countsize_type count(const Key& key) const;
The member function returns the number of elements x
in the range [lower_bound(key), upper_b3und(key)).
multiset::difference_typetypedef typename A::difference_type difference_type;
The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.
multiset::emptybool empty() const;
The member function returns true for an empty controlled sequence.
multiset::endconst_iterator end() const;
The member function returns a bidirectional iterator that points just beyond the end of the sequence.
multiset::equal_rangepair<const_iterator, const_iterator>
equal_range(const Key& key) const;
The member function returns a pair of iterators x
such that x.first == lower_bound(key)
and x.second == upper_bound(key).
multiset::eraseiterator erase(iterator it); iterator erase(iterator first, iterator last); size_type erase(const Key& key);
The first member function removes the element of the
controlled sequence pointed to by it. The second
member function removes the elements in the range [first,
last). Both return an iterator that designates the first
element remaining beyond any elements removed, or end()
if no such element exists.
The third member removes the elements with sort keys in the
range [lower_bound(key), upper_bound(key)).
It returns the number of elements it removes.
multiset::findconst_iterator find(const Key& key) const;
The member function returns an iterator that designates the
earliest element in the controlled sequence whose sort key equals
key. If no such element exists, the iterator equals end().
multiset::get_allocatorA get_allocator() const;
The member function returns allocator.
multiset::insertiterator insert(const value_type& x);
iterator insert(iterator it, const value_type& x);
template<class InIt>
void insert(InIt first, InIt last);
The first member function inserts the element x
in the controlled sequence, then returns the iterator that
designates the inserted element. The second member function
returns insert(x), using it as a
starting place within the controlled sequence to search for the
insertion point. (Insertion can occur in amortized constant time,
instead of logarithmic time, if the insertion point immediately
follows it.) The third member function inserts the
sequence of element values in the range [first, last).
multiset::iteratortypedef T0 iterator;
The type describes an object that can serve as a bidirectional
iterator for the controlled sequence. It is described here as a
synonym for the unspecified type T0.
multiset::key_compkey_compare key_comp() const;
The member function returns the stored function object that determines the order of elements in the controlled sequence. The stored object defines the member function:
bool operator(const Key& x, const Key& y);
which returns true if x strictly precedes y
in the sort order.
multiset::key_comparetypedef Pred key_compare;
The type describes a function object that can compare two sort keys to determine the relative order of any two elements in the controlled sequence.
multiset::key_typetypedef Key key_type;
The type describes the sort key object which constitutes each element of the controlled sequence.
multiset::lower_boundconst_iterator lower_bound(const Key& key) const;
The member function returns an iterator that designates the
earliest element x in the controlled sequence for
which key_comp()(x, key)
is false.
If no such element exists, the function returns end().
multiset::multisetmultiset();
explicit multiset(const Pred& comp);
multiset(const Pred& comp, const A& al);
multiset(const multiset& x);
template<class InIt>
multiset(InIt first, InIt last);
template<class InIt>
multiset(InIt first, InIt last,
const Pred& comp);
template<class InIt>
multiset(InIt first, InIt last,
const Pred& comp, const A& al);
All constructors store an allocator object in allocator
and initialize the controlled sequence. The allocator object is
the argument al, if present. For the copy
constructor, it is x.get_allocator().
Otherwise, it is A().
All constructors also store a function object that can later
be returned by calling key_comp(). The
function object is the argument comp, if present.
For the copy constructor, it is x.key_comp()).
Otherwise, it is Pred().
The first three constructors specify an empty initial
controlled sequence. The fourth constructor specifies a copy of
the sequence controlled by x. The last three
constructors specify the sequence of element values [first,
last).
multiset::max_sizesize_type max_size() const;
The member function returns the length of the longest sequence that the object can control.
multiset::rbeginconst_reverse_iterator rbegin() const;
The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
multiset::referencetypedef typename A::rebind<value_type>::other::const_reference
reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
multiset::rendconst_reverse_iterator rend() const;
The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.
multiset::reverse_iteratortypedef reverse_iterator<iterator> reverse_iterator;
The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.
multiset::sizesize_type size() const;
The member function returns the length of the controlled sequence.
multiset::size_typetypedef typename A::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
multiset::swapvoid swap(multiset& str);
The member function swaps the controlled sequences between *this
and str. If allocator ==
str.allocator, it does so in constant time; and it throws
an exception only as a result of copying the stored function
object of type Pred. Otherwise, it performs a number
of element assignments and constructor calls proportional to the
number of elements in the two controlled sequences.
multiset::upper_boundconst_iterator upper_bound(const Key& key) const;
The member function returns an iterator that designates the
earliest element x in the controlled sequence for
which key_comp()(key, x)
is true.
If no such element exists, the function returns end().
multiset::value_compvalue_compare value_comp() const;
The member function returns a function object that determines the order of elements in the controlled sequence.
multiset::value_comparetypedef Pred value_compare;
The type describes a function object that can compare two elements as sort keys to determine their relative order in the controlled sequence.
multiset::value_typetypedef Key value_type;
The type describes an element of the controlled sequence.
operator!=template<class Key, class Pred, class A>
bool operator!=(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator!=(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The template function returns !(lhs == rhs).
operator==template<class Key, class Pred, class A>
bool operator==(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator==(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The first template function overloads operator==
to compare two objects of template class multiset. The second
template function overloads operator== to compare
two objects of template class multiset. Both
functions return lhs.size() == rhs.size()
&& equal(lhs. begin(),
lhs. end(),
rhs.begin()).
operator<template<class Key, class Pred, class A>
bool operator<(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The first template function overloads operator<
to compare two objects of template class multiset. The second
template function overloads operator< to compare
two objects of template class multiset. Both
functions return lexicographical_compare(lhs.
begin(),
lhs. end(),
rhs.begin(), rhs.end()).
operator<=template<class Key, class Pred, class A>
bool operator<=(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<=(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The template function returns !(rhs < lhs).
operator>template<class Key, class Pred, class A>
bool operator>(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The template function returns rhs < lhs.
operator>=template<class Key, class Pred, class A>
bool operator>=(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>=(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
The template function returns !(lhs < rhs).
setallocator_type · begin · clear · const_iterator
· const_reference
· const_reverse_iterator
· count ·
difference_type
· empty ·
end · equal_range
· erase ·
find · get_allocator
· insert
· iterator
· key_comp
· key_compare
· key_type
· lower_bound
· set · max_size ·
rbegin · reference
· rend · reverse_iterator
· size · size_type
· swap · upper_bound
· value_comp
· value_compare
· value_type
template<class Key, class Pred = less<Key>,
class A = allocator<T> >
class set {
public:
typedef Key key_type;
typedef Pred key_compare;
typedef Key value_type;
typedef Pred value_compare;
typedef A allocator_type;
typedef typename A::size_type size_type;
typedef typename A::difference_type difference_type;
typedef typename A::rebind<value_type>::other::const_reference
reference;
typedef typename A::rebind<value_type>::other::const_reference
const_reference;
typedef T0 iterator;
typedef T1 const_iterator;
typedef reverse_iterator<const_iterator>
const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
set();
explicit set(const Pred& comp);
set(const Pred& comp, const A& al);
set(const set& x);
template<class InIt>
set(InIt first, InIt last);
template<class InIt>
set(InIt first, InIt last,
const Pred& comp);
template<class InIt>
set(InIt first, InIt last,
const Pred& comp, const A& al);
const_iterator begin() const;
iterator end() const;
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
size_type size() const;
size_type max_size() const;
bool empty() const;
A get_allocator() const;
pair<iterator, bool> insert(const value_type& x);
iterator insert(iterator it, const value_type& x);
template<class InIt>
void insert(InIt first, InIt last);
iterator erase(iterator it);
iterator erase(iterator first, iterator last);
size_type erase(const Key& key);
void clear();
void swap(set x);
key_compare key_comp() const;
value_compare value_comp() const;
const_iterator find(const Key& key) const;
size_type count(const Key& key) const;
const_iterator lower_bound(const Key& key) const;
const_iterator upper_bound(const Key& key) const;
pair<const_iterator, const_iterator>
equal_range(const Key& key) const;
protected:
A allocator;
};
The template class describes an object that controls a
varying-length sequence of elements of type const Key.
Each element serves as both a sort key and a value.
The sequence is represented in a way that permits lookup,
insertion, and removal of an arbitrary element with a number of
operations proportional to the logarithm of the number of
elements in the sequence (logarithmic time). Moreover, inserting
an element invalidates no iterators, and removing an element
invalidates only those iterators which point at the removed
element.
The object orders the sequence it controls by calling a stored
function object of type Pred. You access this
stored object by calling the member function key_comp().
Such a function object must impose a total order on sort keys.
For any element x that precedes y in
the sequence, key_comp()(y, x) is false. (For the
default function object less<Key>,
sort keys never decrease in value.) Unlike template class multiset,
an object of template class set ensures that key_comp()(x,
y) is true. (Each key is unique.)
The object allocates and frees storage for the sequence it
controls through a protected object named allocator, of class
A. Such an allocator
object must have the same external interface as an object of
template class allocator.
Note that allocator is not copied when the
object is assigned.
set::allocator_typetypedef A allocator_type;
The type is a synonym for the template parameter A.
set::beginconst_iterator begin() const;
The member function returns a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
set::clearvoid clear();
The member function calls erase( begin(), end()).
set::const_iteratortypedef T1 const_iterator;
The type describes an object that can serve as a constant
bidirectional iterator for the controlled sequence. It is
desciibed here as a synonym for the unspecified type T1.
set::const_referencetypedef typename A::rebind<value_type>::other::const_reference
const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
set::const_reverse_iteratortypedef reverse_iterator<const_iterator>
const_reverse_iterator;
The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.
set::countsize_type count(const Key& key) const;
The member function returns the number of elements x
in the range [lower_bound(key), upper_bound(key)).
set::difference_typetypedef typename A::difference_type difference_type;
The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.
set::emptybool empty() const;
The member function returns true for an empty controlled sequence.
set::endconst_iterator end() const;
The member function returns a bidirectional iterator that points just beyond the end of the sequence.
set::equal_rangepair<const_iterator, const_iterator>
equal_range(const Key& key) const;
The member function returns a pair of iterators x
such that x.first == lower_bound(key)
and x.second == upper_bound(key).
set::eraseiterator erase(iterator it); iterator erase(iterator first, iterator last); size_type erase(const Key& key);
The first member function removes the element of the
controlled sequence pointed to by it. The second
member function removes the elements in the range [first,
last). Both return an iterator that designates the first
element remaining beyond any elements removed, or end() if
no such element exists.
The third member removes the elements with sort keys in the
range [lower_bound(key), upper_bound(key)).
It returns the number of elements it removes.
set::findconst_iterator find(const Key& key) const;
The member function returns an iterator that designates the
earliest element in the controlled sequence whose sort key equals
key. If no such element exists, the iterator equals end().
set::get_allocatorA get_allocator() const;
The member function returns allocator.
set::insertpair<iterator, bool> insert(const value_type& x);
iterator insert(iterator it, const value_type& x);
template<class InIt>
void insert(InIt first, InIt last);
The first member function determines whether an element y
exists in the sequence whose key matches that of x.
(The keys match if !key_comp()(x, y) &&
!key_comp()(y, x).) If not, it creates such an element y
and initializes it with x. The function then
determines the iterator it that designates y.
If an insertion occurred, the function returns pair(it, true). Otherwise, it
returns pair(it, false).
The second member function returns insert(x),
using it as a starting place within the controlled
sequence to search for the insertion point. (Insertion can occur
in amortized constant time, instead of logarithmic time, if the
insertion point immediately follows it.) The third
member function inserts the sequence of element values in the
range [first, last).
set::iteratortypedef T0 iterator;
The type describes an object that can serve as a bidirectional
iterator for the controlled sequence. It is described here as a
synonym for the unspecified type T0.
set::key_compkey_compare key_comp() const;
The member function returns the stored function object that determines the order of elements in the controlled sequence. The stored object defines the member function:
bool operator(const Key& x, const Key& y);
which returns true if x strictly precedes y
in the sort order.
set::key_comparetypedef Pred key_compare;
The type describes a function object that can compare two sort keys to determine the relative order of any two elements in the controlled sequence.
set::key_typetypedef Key key_type;
The type describes the sort key object which constitutes each element of the controlled sequence.
set::lower_boundconst_iterator lower_bound(const Key& key) const;
The member function returns an iterator that designates the
earliest element x in the controlled sequence for
which key_comp()(x,
key) is false.
If no such element exists, the function returns end().
set::max_sizesize_type max_size() const;
The member function returns the length of the longest sequence that the object can control.
set::rbeginconst_reverse_iterator rbegin() const;
The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
set::referencetypedef typename A::rebind<value_type>::other::const_reference
reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
set::rendconst_reverse_iterator rend() const;
The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.
set::reverse_iteratortypedef reverse_iterator<iterator> reverse_iterator;
The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.
set::setset();
explicit set(const Pred& comp);
set(const Pred& comp, const A& al);
set(const set& x);
template<class InIt>
set(InIt first, InIt last);
template<class InIt>
set(InIt first, InIt last,
const Pred& comp);
template<class InIt>
set(InIt first, InIt last,
const Pred& comp, const A& al);
All constructors store an allocator object in allocator
and initialize the controlled sequence. The allocator object is
the argument al, if present. For the copy
constructor, it is x.get_allocator().
Otherwise, it is A().
All constructors also store a function object that can later
be returned by calling key_comp(). The
function object is the argument comp, if present.
For the copy constructor, it is x.key_comp()).
Otherwise, it is Pred().
The first three constructors specify an empty initial
controlled sequence. The fourth constructor specifies a copy of
the sequence controlled by x. The last three
constructors specify the sequence of element values [first,
last).
set::sizesize_type size() const;
The member function returns the length of the controlled sequence.
set::size_typetypedef typename A::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
set::swapvoid swap(set& str);
The member function swaps the controlled sequences between *this
and str. If allocator == str.allocator,
it does so in constant time; and it throws an exception only as a
result of copying the stored function object of type Pred.
Otherwise, it performs a number of element assignments and
constructor calls proportional to the number of elements in the
two controlled sequences.
set::upper_boundconst_iterator upper_bound(const Key& key) const;
The member function returns an iterator that designates the
earliest element x in the controlled sequence for
which key_comp()(key,
x) is true.
If no such element exists, the function returns end().
set::value_compvalue_compare value_comp() const;
The member function returns a function object that determines the order of elements in the controlled sequence.
set::value_comparetypedef Pred value_compare;
The type describes a function object that can compare two elements as sort keys to determine their relative order in the controlled sequence.
set::value_typetypedef Key value_type;
The type describes an element of the controlled sequence.
swaptemplate<class Key, class Pred, class A>
void swap(
const multiset <Key, Pred, A>& lhs,
const multiset <Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
void swap(
const set <Key, Pred, A>& lhs,
const set <Key, Pred, A>& rhs);
The template function executes lhs.swap(rhs).
See also the Table of Contents .
Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.