libstdc++
|
00001 // Multiset implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001-2016 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /* 00026 * 00027 * Copyright (c) 1994 00028 * Hewlett-Packard Company 00029 * 00030 * Permission to use, copy, modify, distribute and sell this software 00031 * and its documentation for any purpose is hereby granted without fee, 00032 * provided that the above copyright notice appear in all copies and 00033 * that both that copyright notice and this permission notice appear 00034 * in supporting documentation. Hewlett-Packard Company makes no 00035 * representations about the suitability of this software for any 00036 * purpose. It is provided "as is" without express or implied warranty. 00037 * 00038 * 00039 * Copyright (c) 1996 00040 * Silicon Graphics Computer Systems, Inc. 00041 * 00042 * Permission to use, copy, modify, distribute and sell this software 00043 * and its documentation for any purpose is hereby granted without fee, 00044 * provided that the above copyright notice appear in all copies and 00045 * that both that copyright notice and this permission notice appear 00046 * in supporting documentation. Silicon Graphics makes no 00047 * representations about the suitability of this software for any 00048 * purpose. It is provided "as is" without express or implied warranty. 00049 */ 00050 00051 /** @file bits/stl_multiset.h 00052 * This is an internal header file, included by other library headers. 00053 * Do not attempt to use it directly. @headername{set} 00054 */ 00055 00056 #ifndef _STL_MULTISET_H 00057 #define _STL_MULTISET_H 1 00058 00059 #include <bits/concept_check.h> 00060 #if __cplusplus >= 201103L 00061 #include <initializer_list> 00062 #endif 00063 00064 namespace std _GLIBCXX_VISIBILITY(default) 00065 { 00066 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 00067 00068 /** 00069 * @brief A standard container made up of elements, which can be retrieved 00070 * in logarithmic time. 00071 * 00072 * @ingroup associative_containers 00073 * 00074 * 00075 * @tparam _Key Type of key objects. 00076 * @tparam _Compare Comparison function object type, defaults to less<_Key>. 00077 * @tparam _Alloc Allocator type, defaults to allocator<_Key>. 00078 * 00079 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00080 * <a href="tables.html#66">reversible container</a>, and an 00081 * <a href="tables.html#69">associative container</a> (using equivalent 00082 * keys). For a @c multiset<Key> the key_type and value_type are Key. 00083 * 00084 * Multisets support bidirectional iterators. 00085 * 00086 * The private tree data is declared exactly the same way for set and 00087 * multiset; the distinction is made entirely in how the tree functions are 00088 * called (*_unique versus *_equal, same as the standard). 00089 */ 00090 template <typename _Key, typename _Compare = std::less<_Key>, 00091 typename _Alloc = std::allocator<_Key> > 00092 class multiset 00093 { 00094 // concept requirements 00095 typedef typename _Alloc::value_type _Alloc_value_type; 00096 __glibcxx_class_requires(_Key, _SGIAssignableConcept) 00097 __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 00098 _BinaryFunctionConcept) 00099 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept) 00100 00101 public: 00102 // typedefs: 00103 typedef _Key key_type; 00104 typedef _Key value_type; 00105 typedef _Compare key_compare; 00106 typedef _Compare value_compare; 00107 typedef _Alloc allocator_type; 00108 00109 private: 00110 /// This turns a red-black tree into a [multi]set. 00111 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template 00112 rebind<_Key>::other _Key_alloc_type; 00113 00114 typedef _Rb_tree<key_type, value_type, _Identity<value_type>, 00115 key_compare, _Key_alloc_type> _Rep_type; 00116 /// The actual tree structure. 00117 _Rep_type _M_t; 00118 00119 typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits; 00120 00121 public: 00122 typedef typename _Alloc_traits::pointer pointer; 00123 typedef typename _Alloc_traits::const_pointer const_pointer; 00124 typedef typename _Alloc_traits::reference reference; 00125 typedef typename _Alloc_traits::const_reference const_reference; 00126 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00127 // DR 103. set::iterator is required to be modifiable, 00128 // but this allows modification of keys. 00129 typedef typename _Rep_type::const_iterator iterator; 00130 typedef typename _Rep_type::const_iterator const_iterator; 00131 typedef typename _Rep_type::const_reverse_iterator reverse_iterator; 00132 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 00133 typedef typename _Rep_type::size_type size_type; 00134 typedef typename _Rep_type::difference_type difference_type; 00135 00136 // allocation/deallocation 00137 /** 00138 * @brief Default constructor creates no elements. 00139 */ 00140 multiset() 00141 _GLIBCXX_NOEXCEPT_IF( 00142 is_nothrow_default_constructible<allocator_type>::value 00143 && is_nothrow_default_constructible<key_compare>::value) 00144 : _M_t() { } 00145 00146 /** 00147 * @brief Creates a %multiset with no elements. 00148 * @param __comp Comparator to use. 00149 * @param __a An allocator object. 00150 */ 00151 explicit 00152 multiset(const _Compare& __comp, 00153 const allocator_type& __a = allocator_type()) 00154 : _M_t(__comp, _Key_alloc_type(__a)) { } 00155 00156 /** 00157 * @brief Builds a %multiset from a range. 00158 * @param __first An input iterator. 00159 * @param __last An input iterator. 00160 * 00161 * Create a %multiset consisting of copies of the elements from 00162 * [first,last). This is linear in N if the range is already sorted, 00163 * and NlogN otherwise (where N is distance(__first,__last)). 00164 */ 00165 template<typename _InputIterator> 00166 multiset(_InputIterator __first, _InputIterator __last) 00167 : _M_t() 00168 { _M_t._M_insert_equal(__first, __last); } 00169 00170 /** 00171 * @brief Builds a %multiset from a range. 00172 * @param __first An input iterator. 00173 * @param __last An input iterator. 00174 * @param __comp A comparison functor. 00175 * @param __a An allocator object. 00176 * 00177 * Create a %multiset consisting of copies of the elements from 00178 * [__first,__last). This is linear in N if the range is already sorted, 00179 * and NlogN otherwise (where N is distance(__first,__last)). 00180 */ 00181 template<typename _InputIterator> 00182 multiset(_InputIterator __first, _InputIterator __last, 00183 const _Compare& __comp, 00184 const allocator_type& __a = allocator_type()) 00185 : _M_t(__comp, _Key_alloc_type(__a)) 00186 { _M_t._M_insert_equal(__first, __last); } 00187 00188 /** 00189 * @brief %Multiset copy constructor. 00190 * @param __x A %multiset of identical element and allocator types. 00191 * 00192 * The newly-created %multiset uses a copy of the allocation object used 00193 * by @a __x. 00194 */ 00195 multiset(const multiset& __x) 00196 : _M_t(__x._M_t) { } 00197 00198 #if __cplusplus >= 201103L 00199 /** 00200 * @brief %Multiset move constructor. 00201 * @param __x A %multiset of identical element and allocator types. 00202 * 00203 * The newly-created %multiset contains the exact contents of @a __x. 00204 * The contents of @a __x are a valid, but unspecified %multiset. 00205 */ 00206 multiset(multiset&& __x) 00207 noexcept(is_nothrow_copy_constructible<_Compare>::value) 00208 : _M_t(std::move(__x._M_t)) { } 00209 00210 /** 00211 * @brief Builds a %multiset from an initializer_list. 00212 * @param __l An initializer_list. 00213 * @param __comp A comparison functor. 00214 * @param __a An allocator object. 00215 * 00216 * Create a %multiset consisting of copies of the elements from 00217 * the list. This is linear in N if the list is already sorted, 00218 * and NlogN otherwise (where N is @a __l.size()). 00219 */ 00220 multiset(initializer_list<value_type> __l, 00221 const _Compare& __comp = _Compare(), 00222 const allocator_type& __a = allocator_type()) 00223 : _M_t(__comp, _Key_alloc_type(__a)) 00224 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00225 00226 /// Allocator-extended default constructor. 00227 explicit 00228 multiset(const allocator_type& __a) 00229 : _M_t(_Compare(), _Key_alloc_type(__a)) { } 00230 00231 /// Allocator-extended copy constructor. 00232 multiset(const multiset& __m, const allocator_type& __a) 00233 : _M_t(__m._M_t, _Key_alloc_type(__a)) { } 00234 00235 /// Allocator-extended move constructor. 00236 multiset(multiset&& __m, const allocator_type& __a) 00237 noexcept(is_nothrow_copy_constructible<_Compare>::value 00238 && _Alloc_traits::_S_always_equal()) 00239 : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { } 00240 00241 /// Allocator-extended initialier-list constructor. 00242 multiset(initializer_list<value_type> __l, const allocator_type& __a) 00243 : _M_t(_Compare(), _Key_alloc_type(__a)) 00244 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00245 00246 /// Allocator-extended range constructor. 00247 template<typename _InputIterator> 00248 multiset(_InputIterator __first, _InputIterator __last, 00249 const allocator_type& __a) 00250 : _M_t(_Compare(), _Key_alloc_type(__a)) 00251 { _M_t._M_insert_equal(__first, __last); } 00252 #endif 00253 00254 /** 00255 * @brief %Multiset assignment operator. 00256 * @param __x A %multiset of identical element and allocator types. 00257 * 00258 * All the elements of @a __x are copied, but unlike the copy 00259 * constructor, the allocator object is not copied. 00260 */ 00261 multiset& 00262 operator=(const multiset& __x) 00263 { 00264 _M_t = __x._M_t; 00265 return *this; 00266 } 00267 00268 #if __cplusplus >= 201103L 00269 /// Move assignment operator. 00270 multiset& 00271 operator=(multiset&&) = default; 00272 00273 /** 00274 * @brief %Multiset list assignment operator. 00275 * @param __l An initializer_list. 00276 * 00277 * This function fills a %multiset with copies of the elements in the 00278 * initializer list @a __l. 00279 * 00280 * Note that the assignment completely changes the %multiset and 00281 * that the resulting %multiset's size is the same as the number 00282 * of elements assigned. Old data may be lost. 00283 */ 00284 multiset& 00285 operator=(initializer_list<value_type> __l) 00286 { 00287 _M_t._M_assign_equal(__l.begin(), __l.end()); 00288 return *this; 00289 } 00290 #endif 00291 00292 // accessors: 00293 00294 /// Returns the comparison object. 00295 key_compare 00296 key_comp() const 00297 { return _M_t.key_comp(); } 00298 /// Returns the comparison object. 00299 value_compare 00300 value_comp() const 00301 { return _M_t.key_comp(); } 00302 /// Returns the memory allocation object. 00303 allocator_type 00304 get_allocator() const _GLIBCXX_NOEXCEPT 00305 { return allocator_type(_M_t.get_allocator()); } 00306 00307 /** 00308 * Returns a read-only (constant) iterator that points to the first 00309 * element in the %multiset. Iteration is done in ascending order 00310 * according to the keys. 00311 */ 00312 iterator 00313 begin() const _GLIBCXX_NOEXCEPT 00314 { return _M_t.begin(); } 00315 00316 /** 00317 * Returns a read-only (constant) iterator that points one past the last 00318 * element in the %multiset. Iteration is done in ascending order 00319 * according to the keys. 00320 */ 00321 iterator 00322 end() const _GLIBCXX_NOEXCEPT 00323 { return _M_t.end(); } 00324 00325 /** 00326 * Returns a read-only (constant) reverse iterator that points to the 00327 * last element in the %multiset. Iteration is done in descending order 00328 * according to the keys. 00329 */ 00330 reverse_iterator 00331 rbegin() const _GLIBCXX_NOEXCEPT 00332 { return _M_t.rbegin(); } 00333 00334 /** 00335 * Returns a read-only (constant) reverse iterator that points to the 00336 * last element in the %multiset. Iteration is done in descending order 00337 * according to the keys. 00338 */ 00339 reverse_iterator 00340 rend() const _GLIBCXX_NOEXCEPT 00341 { return _M_t.rend(); } 00342 00343 #if __cplusplus >= 201103L 00344 /** 00345 * Returns a read-only (constant) iterator that points to the first 00346 * element in the %multiset. Iteration is done in ascending order 00347 * according to the keys. 00348 */ 00349 iterator 00350 cbegin() const noexcept 00351 { return _M_t.begin(); } 00352 00353 /** 00354 * Returns a read-only (constant) iterator that points one past the last 00355 * element in the %multiset. Iteration is done in ascending order 00356 * according to the keys. 00357 */ 00358 iterator 00359 cend() const noexcept 00360 { return _M_t.end(); } 00361 00362 /** 00363 * Returns a read-only (constant) reverse iterator that points to the 00364 * last element in the %multiset. Iteration is done in descending order 00365 * according to the keys. 00366 */ 00367 reverse_iterator 00368 crbegin() const noexcept 00369 { return _M_t.rbegin(); } 00370 00371 /** 00372 * Returns a read-only (constant) reverse iterator that points to the 00373 * last element in the %multiset. Iteration is done in descending order 00374 * according to the keys. 00375 */ 00376 reverse_iterator 00377 crend() const noexcept 00378 { return _M_t.rend(); } 00379 #endif 00380 00381 /// Returns true if the %set is empty. 00382 bool 00383 empty() const _GLIBCXX_NOEXCEPT 00384 { return _M_t.empty(); } 00385 00386 /// Returns the size of the %set. 00387 size_type 00388 size() const _GLIBCXX_NOEXCEPT 00389 { return _M_t.size(); } 00390 00391 /// Returns the maximum size of the %set. 00392 size_type 00393 max_size() const _GLIBCXX_NOEXCEPT 00394 { return _M_t.max_size(); } 00395 00396 /** 00397 * @brief Swaps data with another %multiset. 00398 * @param __x A %multiset of the same element and allocator types. 00399 * 00400 * This exchanges the elements between two multisets in constant time. 00401 * (It is only swapping a pointer, an integer, and an instance of the @c 00402 * Compare type (which itself is often stateless and empty), so it should 00403 * be quite fast.) 00404 * Note that the global std::swap() function is specialized such that 00405 * std::swap(s1,s2) will feed to this function. 00406 */ 00407 void 00408 swap(multiset& __x) 00409 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) 00410 { _M_t.swap(__x._M_t); } 00411 00412 // insert/erase 00413 #if __cplusplus >= 201103L 00414 /** 00415 * @brief Builds and inserts an element into the %multiset. 00416 * @param __args Arguments used to generate the element instance to be 00417 * inserted. 00418 * @return An iterator that points to the inserted element. 00419 * 00420 * This function inserts an element into the %multiset. Contrary 00421 * to a std::set the %multiset does not rely on unique keys and thus 00422 * multiple copies of the same element can be inserted. 00423 * 00424 * Insertion requires logarithmic time. 00425 */ 00426 template<typename... _Args> 00427 iterator 00428 emplace(_Args&&... __args) 00429 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } 00430 00431 /** 00432 * @brief Builds and inserts an element into the %multiset. 00433 * @param __pos An iterator that serves as a hint as to where the 00434 * element should be inserted. 00435 * @param __args Arguments used to generate the element instance to be 00436 * inserted. 00437 * @return An iterator that points to the inserted element. 00438 * 00439 * This function inserts an element into the %multiset. Contrary 00440 * to a std::set the %multiset does not rely on unique keys and thus 00441 * multiple copies of the same element can be inserted. 00442 * 00443 * Note that the first parameter is only a hint and can potentially 00444 * improve the performance of the insertion process. A bad hint would 00445 * cause no gains in efficiency. 00446 * 00447 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00448 * for more on @a hinting. 00449 * 00450 * Insertion requires logarithmic time (if the hint is not taken). 00451 */ 00452 template<typename... _Args> 00453 iterator 00454 emplace_hint(const_iterator __pos, _Args&&... __args) 00455 { 00456 return _M_t._M_emplace_hint_equal(__pos, 00457 std::forward<_Args>(__args)...); 00458 } 00459 #endif 00460 00461 /** 00462 * @brief Inserts an element into the %multiset. 00463 * @param __x Element to be inserted. 00464 * @return An iterator that points to the inserted element. 00465 * 00466 * This function inserts an element into the %multiset. Contrary 00467 * to a std::set the %multiset does not rely on unique keys and thus 00468 * multiple copies of the same element can be inserted. 00469 * 00470 * Insertion requires logarithmic time. 00471 */ 00472 iterator 00473 insert(const value_type& __x) 00474 { return _M_t._M_insert_equal(__x); } 00475 00476 #if __cplusplus >= 201103L 00477 iterator 00478 insert(value_type&& __x) 00479 { return _M_t._M_insert_equal(std::move(__x)); } 00480 #endif 00481 00482 /** 00483 * @brief Inserts an element into the %multiset. 00484 * @param __position An iterator that serves as a hint as to where the 00485 * element should be inserted. 00486 * @param __x Element to be inserted. 00487 * @return An iterator that points to the inserted element. 00488 * 00489 * This function inserts an element into the %multiset. Contrary 00490 * to a std::set the %multiset does not rely on unique keys and thus 00491 * multiple copies of the same element can be inserted. 00492 * 00493 * Note that the first parameter is only a hint and can potentially 00494 * improve the performance of the insertion process. A bad hint would 00495 * cause no gains in efficiency. 00496 * 00497 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00498 * for more on @a hinting. 00499 * 00500 * Insertion requires logarithmic time (if the hint is not taken). 00501 */ 00502 iterator 00503 insert(const_iterator __position, const value_type& __x) 00504 { return _M_t._M_insert_equal_(__position, __x); } 00505 00506 #if __cplusplus >= 201103L 00507 iterator 00508 insert(const_iterator __position, value_type&& __x) 00509 { return _M_t._M_insert_equal_(__position, std::move(__x)); } 00510 #endif 00511 00512 /** 00513 * @brief A template function that tries to insert a range of elements. 00514 * @param __first Iterator pointing to the start of the range to be 00515 * inserted. 00516 * @param __last Iterator pointing to the end of the range. 00517 * 00518 * Complexity similar to that of the range constructor. 00519 */ 00520 template<typename _InputIterator> 00521 void 00522 insert(_InputIterator __first, _InputIterator __last) 00523 { _M_t._M_insert_equal(__first, __last); } 00524 00525 #if __cplusplus >= 201103L 00526 /** 00527 * @brief Attempts to insert a list of elements into the %multiset. 00528 * @param __l A std::initializer_list<value_type> of elements 00529 * to be inserted. 00530 * 00531 * Complexity similar to that of the range constructor. 00532 */ 00533 void 00534 insert(initializer_list<value_type> __l) 00535 { this->insert(__l.begin(), __l.end()); } 00536 #endif 00537 00538 #if __cplusplus >= 201103L 00539 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00540 // DR 130. Associative erase should return an iterator. 00541 /** 00542 * @brief Erases an element from a %multiset. 00543 * @param __position An iterator pointing to the element to be erased. 00544 * @return An iterator pointing to the element immediately following 00545 * @a position prior to the element being erased. If no such 00546 * element exists, end() is returned. 00547 * 00548 * This function erases an element, pointed to by the given iterator, 00549 * from a %multiset. Note that this function only erases the element, 00550 * and that if the element is itself a pointer, the pointed-to memory is 00551 * not touched in any way. Managing the pointer is the user's 00552 * responsibility. 00553 */ 00554 _GLIBCXX_ABI_TAG_CXX11 00555 iterator 00556 erase(const_iterator __position) 00557 { return _M_t.erase(__position); } 00558 #else 00559 /** 00560 * @brief Erases an element from a %multiset. 00561 * @param __position An iterator pointing to the element to be erased. 00562 * 00563 * This function erases an element, pointed to by the given iterator, 00564 * from a %multiset. Note that this function only erases the element, 00565 * and that if the element is itself a pointer, the pointed-to memory is 00566 * not touched in any way. Managing the pointer is the user's 00567 * responsibility. 00568 */ 00569 void 00570 erase(iterator __position) 00571 { _M_t.erase(__position); } 00572 #endif 00573 00574 /** 00575 * @brief Erases elements according to the provided key. 00576 * @param __x Key of element to be erased. 00577 * @return The number of elements erased. 00578 * 00579 * This function erases all elements located by the given key from a 00580 * %multiset. 00581 * Note that this function only erases the element, and that if 00582 * the element is itself a pointer, the pointed-to memory is not touched 00583 * in any way. Managing the pointer is the user's responsibility. 00584 */ 00585 size_type 00586 erase(const key_type& __x) 00587 { return _M_t.erase(__x); } 00588 00589 #if __cplusplus >= 201103L 00590 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00591 // DR 130. Associative erase should return an iterator. 00592 /** 00593 * @brief Erases a [first,last) range of elements from a %multiset. 00594 * @param __first Iterator pointing to the start of the range to be 00595 * erased. 00596 * @param __last Iterator pointing to the end of the range to 00597 * be erased. 00598 * @return The iterator @a last. 00599 * 00600 * This function erases a sequence of elements from a %multiset. 00601 * Note that this function only erases the elements, and that if 00602 * the elements themselves are pointers, the pointed-to memory is not 00603 * touched in any way. Managing the pointer is the user's 00604 * responsibility. 00605 */ 00606 _GLIBCXX_ABI_TAG_CXX11 00607 iterator 00608 erase(const_iterator __first, const_iterator __last) 00609 { return _M_t.erase(__first, __last); } 00610 #else 00611 /** 00612 * @brief Erases a [first,last) range of elements from a %multiset. 00613 * @param first Iterator pointing to the start of the range to be 00614 * erased. 00615 * @param last Iterator pointing to the end of the range to be erased. 00616 * 00617 * This function erases a sequence of elements from a %multiset. 00618 * Note that this function only erases the elements, and that if 00619 * the elements themselves are pointers, the pointed-to memory is not 00620 * touched in any way. Managing the pointer is the user's 00621 * responsibility. 00622 */ 00623 void 00624 erase(iterator __first, iterator __last) 00625 { _M_t.erase(__first, __last); } 00626 #endif 00627 00628 /** 00629 * Erases all elements in a %multiset. Note that this function only 00630 * erases the elements, and that if the elements themselves are pointers, 00631 * the pointed-to memory is not touched in any way. Managing the pointer 00632 * is the user's responsibility. 00633 */ 00634 void 00635 clear() _GLIBCXX_NOEXCEPT 00636 { _M_t.clear(); } 00637 00638 // multiset operations: 00639 00640 //@{ 00641 /** 00642 * @brief Finds the number of elements with given key. 00643 * @param __x Key of elements to be located. 00644 * @return Number of elements with specified key. 00645 */ 00646 size_type 00647 count(const key_type& __x) const 00648 { return _M_t.count(__x); } 00649 00650 #if __cplusplus > 201103L 00651 template<typename _Kt> 00652 auto 00653 count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 00654 { return _M_t._M_count_tr(__x); } 00655 #endif 00656 //@} 00657 00658 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00659 // 214. set::find() missing const overload 00660 //@{ 00661 /** 00662 * @brief Tries to locate an element in a %set. 00663 * @param __x Element to be located. 00664 * @return Iterator pointing to sought-after element, or end() if not 00665 * found. 00666 * 00667 * This function takes a key and tries to locate the element with which 00668 * the key matches. If successful the function returns an iterator 00669 * pointing to the sought after element. If unsuccessful it returns the 00670 * past-the-end ( @c end() ) iterator. 00671 */ 00672 iterator 00673 find(const key_type& __x) 00674 { return _M_t.find(__x); } 00675 00676 const_iterator 00677 find(const key_type& __x) const 00678 { return _M_t.find(__x); } 00679 00680 #if __cplusplus > 201103L 00681 template<typename _Kt> 00682 auto 00683 find(const _Kt& __x) 00684 -> decltype(iterator{_M_t._M_find_tr(__x)}) 00685 { return iterator{_M_t._M_find_tr(__x)}; } 00686 00687 template<typename _Kt> 00688 auto 00689 find(const _Kt& __x) const 00690 -> decltype(const_iterator{_M_t._M_find_tr(__x)}) 00691 { return const_iterator{_M_t._M_find_tr(__x)}; } 00692 #endif 00693 //@} 00694 00695 //@{ 00696 /** 00697 * @brief Finds the beginning of a subsequence matching given key. 00698 * @param __x Key to be located. 00699 * @return Iterator pointing to first element equal to or greater 00700 * than key, or end(). 00701 * 00702 * This function returns the first element of a subsequence of elements 00703 * that matches the given key. If unsuccessful it returns an iterator 00704 * pointing to the first element that has a greater value than given key 00705 * or end() if no such element exists. 00706 */ 00707 iterator 00708 lower_bound(const key_type& __x) 00709 { return _M_t.lower_bound(__x); } 00710 00711 const_iterator 00712 lower_bound(const key_type& __x) const 00713 { return _M_t.lower_bound(__x); } 00714 00715 #if __cplusplus > 201103L 00716 template<typename _Kt> 00717 auto 00718 lower_bound(const _Kt& __x) 00719 -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) 00720 { return iterator(_M_t._M_lower_bound_tr(__x)); } 00721 00722 template<typename _Kt> 00723 auto 00724 lower_bound(const _Kt& __x) const 00725 -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) 00726 { return iterator(_M_t._M_lower_bound_tr(__x)); } 00727 #endif 00728 //@} 00729 00730 //@{ 00731 /** 00732 * @brief Finds the end of a subsequence matching given key. 00733 * @param __x Key to be located. 00734 * @return Iterator pointing to the first element 00735 * greater than key, or end(). 00736 */ 00737 iterator 00738 upper_bound(const key_type& __x) 00739 { return _M_t.upper_bound(__x); } 00740 00741 const_iterator 00742 upper_bound(const key_type& __x) const 00743 { return _M_t.upper_bound(__x); } 00744 00745 #if __cplusplus > 201103L 00746 template<typename _Kt> 00747 auto 00748 upper_bound(const _Kt& __x) 00749 -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) 00750 { return iterator(_M_t._M_upper_bound_tr(__x)); } 00751 00752 template<typename _Kt> 00753 auto 00754 upper_bound(const _Kt& __x) const 00755 -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) 00756 { return iterator(_M_t._M_upper_bound_tr(__x)); } 00757 #endif 00758 //@} 00759 00760 //@{ 00761 /** 00762 * @brief Finds a subsequence matching given key. 00763 * @param __x Key to be located. 00764 * @return Pair of iterators that possibly points to the subsequence 00765 * matching given key. 00766 * 00767 * This function is equivalent to 00768 * @code 00769 * std::make_pair(c.lower_bound(val), 00770 * c.upper_bound(val)) 00771 * @endcode 00772 * (but is faster than making the calls separately). 00773 * 00774 * This function probably only makes sense for multisets. 00775 */ 00776 std::pair<iterator, iterator> 00777 equal_range(const key_type& __x) 00778 { return _M_t.equal_range(__x); } 00779 00780 std::pair<const_iterator, const_iterator> 00781 equal_range(const key_type& __x) const 00782 { return _M_t.equal_range(__x); } 00783 00784 #if __cplusplus > 201103L 00785 template<typename _Kt> 00786 auto 00787 equal_range(const _Kt& __x) 00788 -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) 00789 { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } 00790 00791 template<typename _Kt> 00792 auto 00793 equal_range(const _Kt& __x) const 00794 -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) 00795 { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } 00796 #endif 00797 //@} 00798 00799 template<typename _K1, typename _C1, typename _A1> 00800 friend bool 00801 operator==(const multiset<_K1, _C1, _A1>&, 00802 const multiset<_K1, _C1, _A1>&); 00803 00804 template<typename _K1, typename _C1, typename _A1> 00805 friend bool 00806 operator< (const multiset<_K1, _C1, _A1>&, 00807 const multiset<_K1, _C1, _A1>&); 00808 }; 00809 00810 /** 00811 * @brief Multiset equality comparison. 00812 * @param __x A %multiset. 00813 * @param __y A %multiset of the same type as @a __x. 00814 * @return True iff the size and elements of the multisets are equal. 00815 * 00816 * This is an equivalence relation. It is linear in the size of the 00817 * multisets. 00818 * Multisets are considered equivalent if their sizes are equal, and if 00819 * corresponding elements compare equal. 00820 */ 00821 template<typename _Key, typename _Compare, typename _Alloc> 00822 inline bool 00823 operator==(const multiset<_Key, _Compare, _Alloc>& __x, 00824 const multiset<_Key, _Compare, _Alloc>& __y) 00825 { return __x._M_t == __y._M_t; } 00826 00827 /** 00828 * @brief Multiset ordering relation. 00829 * @param __x A %multiset. 00830 * @param __y A %multiset of the same type as @a __x. 00831 * @return True iff @a __x is lexicographically less than @a __y. 00832 * 00833 * This is a total ordering relation. It is linear in the size of the 00834 * sets. The elements must be comparable with @c <. 00835 * 00836 * See std::lexicographical_compare() for how the determination is made. 00837 */ 00838 template<typename _Key, typename _Compare, typename _Alloc> 00839 inline bool 00840 operator<(const multiset<_Key, _Compare, _Alloc>& __x, 00841 const multiset<_Key, _Compare, _Alloc>& __y) 00842 { return __x._M_t < __y._M_t; } 00843 00844 /// Returns !(x == y). 00845 template<typename _Key, typename _Compare, typename _Alloc> 00846 inline bool 00847 operator!=(const multiset<_Key, _Compare, _Alloc>& __x, 00848 const multiset<_Key, _Compare, _Alloc>& __y) 00849 { return !(__x == __y); } 00850 00851 /// Returns y < x. 00852 template<typename _Key, typename _Compare, typename _Alloc> 00853 inline bool 00854 operator>(const multiset<_Key,_Compare,_Alloc>& __x, 00855 const multiset<_Key,_Compare,_Alloc>& __y) 00856 { return __y < __x; } 00857 00858 /// Returns !(y < x) 00859 template<typename _Key, typename _Compare, typename _Alloc> 00860 inline bool 00861 operator<=(const multiset<_Key, _Compare, _Alloc>& __x, 00862 const multiset<_Key, _Compare, _Alloc>& __y) 00863 { return !(__y < __x); } 00864 00865 /// Returns !(x < y) 00866 template<typename _Key, typename _Compare, typename _Alloc> 00867 inline bool 00868 operator>=(const multiset<_Key, _Compare, _Alloc>& __x, 00869 const multiset<_Key, _Compare, _Alloc>& __y) 00870 { return !(__x < __y); } 00871 00872 /// See std::multiset::swap(). 00873 template<typename _Key, typename _Compare, typename _Alloc> 00874 inline void 00875 swap(multiset<_Key, _Compare, _Alloc>& __x, 00876 multiset<_Key, _Compare, _Alloc>& __y) 00877 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) 00878 { __x.swap(__y); } 00879 00880 _GLIBCXX_END_NAMESPACE_CONTAINER 00881 } // namespace std 00882 00883 #endif /* _STL_MULTISET_H */