A standard container made up of unique keys, which can be retrieved in logarithmic time.
- Template Parameters
-
_Key | Type of key objects. |
_Compare | Comparison function object type, defaults to less<_Key>. |
_Alloc | Allocator type, defaults to allocator<_Key>. |
Meets the requirements of a container, a reversible container, and an associative container (using unique keys).
Sets support bidirectional iterators.
The private tree data is declared exactly the same way for set and multiset; the distinction is made entirely in how the tree functions are called (*_unique versus *_equal, same as the standard).
Public typedefs.
Iterator-related typedefs.
Default constructor creates no elements.
Creates a set with no elements.
- Parameters
-
__comp | Comparator to use. |
__a | An allocator object. |
Builds a set from a range.
- Parameters
-
__first | An input iterator. |
__last | An input iterator. |
Create a set consisting of copies of the elements from [__first,__last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).
Builds a set from a range.
- Parameters
-
__first | An input iterator. |
__last | An input iterator. |
__comp | A comparison functor. |
__a | An allocator object. |
Create a set consisting of copies of the elements from [__first,__last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).
Set copy constructor.
- Parameters
-
__x | A set of identical element and allocator types. |
The newly-created set uses a copy of the allocation object used by __x.
Set assignment operator.
- Parameters
-
__x | A set of identical element and allocator types. |
All the elements of __x are copied, but unlike the copy constructor, the allocator object is not copied.
Returns the comparison object with which the set was constructed.
Returns the comparison object with which the set was constructed.
Returns the allocator object with which the set was constructed.
Returns a read-only (constant) iterator that points to the first element in the set. Iteration is done in ascending order according to the keys.
Returns a read-only (constant) iterator that points one past the last element in the set. Iteration is done in ascending order according to the keys.
Returns a read-only (constant) iterator that points to the last element in the set. Iteration is done in descending order according to the keys.
Returns a read-only (constant) reverse iterator that points to the last pair in the set. Iteration is done in descending order according to the keys.
Returns true if the set is empty.
Returns the size of the set.
Returns the maximum size of the set.
Swaps data with another set.
- Parameters
-
__x | A set of the same element and allocator types. |
This exchanges the elements between two sets in constant time. (It is only swapping a pointer, an integer, and an instance of the Compare
type (which itself is often stateless and empty), so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(s1,s2) will feed to this function.
Attempts to insert an element into the set.
- Parameters
-
__x | Element to be inserted. |
- Returns
- A pair, of which the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted.
This function attempts to insert an element into the set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set.
Insertion requires logarithmic time.
Attempts to insert an element into the set.
- Parameters
-
__position | An iterator that serves as a hint as to where the element should be inserted. |
__x | Element to be inserted. |
- Returns
- An iterator that points to the element with key of __x (may or may not be the element passed in).
This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency.
For more on hinting, see: http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
Insertion requires logarithmic time (if the hint is not taken).
A template function that attempts to insert a range of elements.
- Parameters
-
__first | Iterator pointing to the start of the range to be inserted. |
__last | Iterator pointing to the end of the range. |
Complexity similar to that of the range constructor.
Erases an element from a set.
- Parameters
-
position | An iterator pointing to the element to be erased. |
This function erases an element, pointed to by the given iterator, from a set. Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases elements according to the provided key.
- Parameters
-
__x | Key of element to be erased. |
- Returns
- The number of elements erased.
This function erases all the elements located by the given key from a set. Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases a [first,last) range of elements from a set.
- Parameters
-
__first | Iterator pointing to the start of the range to be erased. |
__last | Iterator pointing to the end of the range to be erased. |
This function erases a sequence of elements from a set. Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases all elements in a set. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Finds the number of elements.
- Parameters
-
- Returns
- Number of elements with specified key.
This function only makes sense for multisets; for set the result will either be 0 (not present) or 1 (present).
Tries to locate an element in a set.
- Parameters
-
__x | Element to be located. |
- Returns
- Iterator pointing to sought-after element, or end() if not found.
This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end ( end()
) iterator.
Finds the beginning of a subsequence matching given key.
- Parameters
-
- Returns
- Iterator pointing to first element equal to or greater than key, or end().
This function returns the first element of a subsequence of elements that matches the given key. If unsuccessful it returns an iterator pointing to the first element that has a greater value than given key or end() if no such element exists.
Finds the end of a subsequence matching given key.
- Parameters
-
- Returns
- Iterator pointing to the first element greater than key, or end().
Finds a subsequence matching given key.
- Parameters
-
- Returns
- Pair of iterators that possibly points to the subsequence matching given key.
This function is equivalent to
std::make_pair(c.lower_bound(val),
c.upper_bound(val))
(but is faster than making the calls separately).
This function probably only makes sense for multisets.
Set equality comparison.
- Parameters
-
__x | A set. |
__y | A set of the same type as x. |
- Returns
- True iff the size and elements of the sets are equal.
This is an equivalence relation. It is linear in the size of the sets. Sets are considered equivalent if their sizes are equal, and if corresponding elements compare equal.
Set ordering relation.
- Parameters
-
__x | A set. |
__y | A set of the same type as x. |
- Returns
- True iff __x is lexicographically less than __y.
This is a total ordering relation. It is linear in the size of the maps. The elements must be comparable with <
.
See std::lexicographical_compare() for how the determination is made.
Returns !(x == y).
Returns y < x.
Returns !(y < x)
Returns !(x < y)
See std::set::swap().
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
88 template<
typename _Key,
typename _Compare = std::less<_Key>,
89 typename _Alloc = std::allocator<_Key> >
93 typedef typename _Alloc::value_type _Alloc_value_type;
96 _BinaryFunctionConcept)
102 typedef _Key key_type;
104 typedef _Key value_type;
105 typedef _Compare key_compare;
106 typedef _Compare value_compare;
107 typedef _Alloc allocator_type;
111 typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
113 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
114 key_compare, _Key_alloc_type> _Rep_type;
119 typedef typename _Key_alloc_type::pointer pointer;
121 typedef typename _Key_alloc_type::const_pointer const_pointer;
122 typedef typename _Key_alloc_type::reference reference;
123 typedef typename _Key_alloc_type::const_reference const_reference;
127 typedef typename _Rep_type::const_iterator iterator;
128 typedef typename _Rep_type::const_iterator const_iterator;
129 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
130 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
131 typedef typename _Rep_type::size_type size_type;
132 typedef typename _Rep_type::difference_type difference_type;
148 set(
const _Compare& __comp,
149 const allocator_type& __a = allocator_type())
150 : _M_t(__comp, _Key_alloc_type(__a)) { }
162 template<
typename _InputIterator>
163 set(_InputIterator __first, _InputIterator __last)
165 { _M_t._M_insert_unique(__first, __last); }
179 template<
typename _InputIterator>
180 set(_InputIterator __first, _InputIterator __last,
181 const _Compare& __comp,
182 const allocator_type& __a = allocator_type())
183 : _M_t(__comp, _Key_alloc_type(__a))
184 { _M_t._M_insert_unique(__first, __last); }
196 #if __cplusplus >= 201103L
205 noexcept(is_nothrow_copy_constructible<_Compare>::value)
206 : _M_t(std::move(__x._M_t)) { }
218 set(initializer_list<value_type> __l,
219 const _Compare& __comp = _Compare(),
220 const allocator_type& __a = allocator_type())
221 : _M_t(__comp, _Key_alloc_type(__a))
222 { _M_t._M_insert_unique(__l.begin(), __l.end()); }
233 operator=(
const set& __x)
239 #if __cplusplus >= 201103L
269 operator=(initializer_list<value_type> __l)
272 this->insert(__l.begin(), __l.end());
282 {
return _M_t.key_comp(); }
286 {
return _M_t.key_comp(); }
289 get_allocator() const _GLIBCXX_NOEXCEPT
290 {
return allocator_type(_M_t.get_allocator()); }
298 begin() const _GLIBCXX_NOEXCEPT
299 {
return _M_t.begin(); }
307 end() const _GLIBCXX_NOEXCEPT
308 {
return _M_t.end(); }
316 rbegin() const _GLIBCXX_NOEXCEPT
317 {
return _M_t.rbegin(); }
325 rend() const _GLIBCXX_NOEXCEPT
326 {
return _M_t.rend(); }
328 #if __cplusplus >= 201103L
335 cbegin() const noexcept
336 {
return _M_t.begin(); }
344 cend() const noexcept
345 {
return _M_t.end(); }
353 crbegin() const noexcept
354 {
return _M_t.rbegin(); }
362 crend() const noexcept
363 {
return _M_t.rend(); }
368 empty() const _GLIBCXX_NOEXCEPT
369 {
return _M_t.empty(); }
373 size() const _GLIBCXX_NOEXCEPT
374 {
return _M_t.size(); }
378 max_size() const _GLIBCXX_NOEXCEPT
379 {
return _M_t.max_size(); }
394 { _M_t.swap(__x._M_t); }
397 #if __cplusplus >= 201103L
411 template<
typename... _Args>
412 std::pair<iterator, bool>
413 emplace(_Args&&... __args)
414 {
return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
437 template<
typename... _Args>
439 emplace_hint(const_iterator __pos, _Args&&... __args)
441 return _M_t._M_emplace_hint_unique(__pos,
442 std::forward<_Args>(__args)...);
459 std::pair<iterator, bool>
460 insert(
const value_type& __x)
462 std::pair<typename _Rep_type::iterator, bool> __p =
463 _M_t._M_insert_unique(__x);
464 return std::pair<iterator, bool>(__p.first, __p.second);
467 #if __cplusplus >= 201103L
468 std::pair<iterator, bool>
469 insert(value_type&& __x)
471 std::pair<typename _Rep_type::iterator, bool> __p =
472 _M_t._M_insert_unique(std::move(__x));
473 return std::pair<iterator, bool>(__p.first, __p.second);
497 insert(const_iterator __position,
const value_type& __x)
498 {
return _M_t._M_insert_unique_(__position, __x); }
500 #if __cplusplus >= 201103L
502 insert(const_iterator __position, value_type&& __x)
503 {
return _M_t._M_insert_unique_(__position, std::move(__x)); }
515 template<
typename _InputIterator>
517 insert(_InputIterator __first, _InputIterator __last)
518 { _M_t._M_insert_unique(__first, __last); }
520 #if __cplusplus >= 201103L
529 insert(initializer_list<value_type> __l)
530 { this->insert(__l.begin(), __l.end()); }
533 #if __cplusplus >= 201103L
549 _GLIBCXX_ABI_TAG_CXX11
551 erase(const_iterator __position)
552 {
return _M_t.erase(__position); }
565 erase(iterator __position)
566 { _M_t.erase(__position); }
581 erase(
const key_type& __x)
582 {
return _M_t.erase(__x); }
584 #if __cplusplus >= 201103L
601 _GLIBCXX_ABI_TAG_CXX11
603 erase(const_iterator __first, const_iterator __last)
604 {
return _M_t.erase(__first, __last); }
619 erase(iterator __first, iterator __last)
620 { _M_t.erase(__first, __last); }
630 clear() _GLIBCXX_NOEXCEPT
644 count(
const key_type& __x)
const
645 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
662 find(
const key_type& __x)
663 {
return _M_t.find(__x); }
666 find(
const key_type& __x)
const
667 {
return _M_t.find(__x); }
683 lower_bound(
const key_type& __x)
684 {
return _M_t.lower_bound(__x); }
687 lower_bound(
const key_type& __x)
const
688 {
return _M_t.lower_bound(__x); }
699 upper_bound(
const key_type& __x)
700 {
return _M_t.upper_bound(__x); }
703 upper_bound(
const key_type& __x)
const
704 {
return _M_t.upper_bound(__x); }
723 std::pair<iterator, iterator>
724 equal_range(
const key_type& __x)
725 {
return _M_t.equal_range(__x); }
727 std::pair<const_iterator, const_iterator>
728 equal_range(
const key_type& __x)
const
729 {
return _M_t.equal_range(__x); }
732 template<
typename _K1,
typename _C1,
typename _A1>
734 operator==(
const set<_K1, _C1, _A1>&,
const set<_K1, _C1, _A1>&);
736 template<
typename _K1,
typename _C1,
typename _A1>
738 operator<(const set<_K1, _C1, _A1>&,
const set<_K1, _C1, _A1>&);
752 template<
typename _Key,
typename _Compare,
typename _Alloc>
754 operator==(
const set<_Key, _Compare, _Alloc>& __x,
755 const set<_Key, _Compare, _Alloc>& __y)
756 {
return __x._M_t == __y._M_t; }
769 template<
typename _Key,
typename _Compare,
typename _Alloc>
771 operator<(const set<_Key, _Compare, _Alloc>& __x,
772 const set<_Key, _Compare, _Alloc>& __y)
773 {
return __x._M_t < __y._M_t; }
776 template<
typename _Key,
typename _Compare,
typename _Alloc>
778 operator!=(
const set<_Key, _Compare, _Alloc>& __x,
779 const set<_Key, _Compare, _Alloc>& __y)
780 {
return !(__x == __y); }
783 template<
typename _Key,
typename _Compare,
typename _Alloc>
785 operator>(
const set<_Key, _Compare, _Alloc>& __x,
786 const set<_Key, _Compare, _Alloc>& __y)
787 {
return __y < __x; }
790 template<
typename _Key,
typename _Compare,
typename _Alloc>
792 operator<=(const set<_Key, _Compare, _Alloc>& __x,
793 const set<_Key, _Compare, _Alloc>& __y)
794 {
return !(__y < __x); }
797 template<
typename _Key,
typename _Compare,
typename _Alloc>
799 operator>=(
const set<_Key, _Compare, _Alloc>& __x,
800 const set<_Key, _Compare, _Alloc>& __y)
801 {
return !(__x < __y); }
804 template<
typename _Key,
typename _Compare,
typename _Alloc>
806 swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
809 _GLIBCXX_END_NAMESPACE_CONTAINER
bool operator>=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:644
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define __glibcxx_class_requires(_a, _b)
Definition: concept_check.h:48
bool operator>(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:612
#define __glibcxx_class_requires2(_a, _b, _c)
Definition: concept_check.h:49
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160
#define __glibcxx_class_requires4(_a, _b, _c, _d, _e)
Definition: concept_check.h:51