libstdc++
|
00001 // Multiset implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001-2015 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 #if __cplusplus >= 201103L 00142 noexcept(is_nothrow_default_constructible<allocator_type>::value) 00143 #endif 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 #if __cplusplus >= 201103L 00410 noexcept(_Alloc_traits::_S_nothrow_swap()) 00411 #endif 00412 { _M_t.swap(__x._M_t); } 00413 00414 // insert/erase 00415 #if __cplusplus >= 201103L 00416 /** 00417 * @brief Builds and inserts an element into the %multiset. 00418 * @param __args Arguments used to generate the element instance to be 00419 * inserted. 00420 * @return An iterator that points to the inserted element. 00421 * 00422 * This function inserts an element into the %multiset. Contrary 00423 * to a std::set the %multiset does not rely on unique keys and thus 00424 * multiple copies of the same element can be inserted. 00425 * 00426 * Insertion requires logarithmic time. 00427 */ 00428 template<typename... _Args> 00429 iterator 00430 emplace(_Args&&... __args) 00431 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } 00432 00433 /** 00434 * @brief Builds and inserts an element into the %multiset. 00435 * @param __pos An iterator that serves as a hint as to where the 00436 * element should be inserted. 00437 * @param __args Arguments used to generate the element instance to be 00438 * inserted. 00439 * @return An iterator that points to the inserted element. 00440 * 00441 * This function inserts an element into the %multiset. Contrary 00442 * to a std::set the %multiset does not rely on unique keys and thus 00443 * multiple copies of the same element can be inserted. 00444 * 00445 * Note that the first parameter is only a hint and can potentially 00446 * improve the performance of the insertion process. A bad hint would 00447 * cause no gains in efficiency. 00448 * 00449 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00450 * for more on @a hinting. 00451 * 00452 * Insertion requires logarithmic time (if the hint is not taken). 00453 */ 00454 template<typename... _Args> 00455 iterator 00456 emplace_hint(const_iterator __pos, _Args&&... __args) 00457 { 00458 return _M_t._M_emplace_hint_equal(__pos, 00459 std::forward<_Args>(__args)...); 00460 } 00461 #endif 00462 00463 /** 00464 * @brief Inserts an element into the %multiset. 00465 * @param __x Element to be inserted. 00466 * @return An iterator that points to the inserted element. 00467 * 00468 * This function inserts an element into the %multiset. Contrary 00469 * to a std::set the %multiset does not rely on unique keys and thus 00470 * multiple copies of the same element can be inserted. 00471 * 00472 * Insertion requires logarithmic time. 00473 */ 00474 iterator 00475 insert(const value_type& __x) 00476 { return _M_t._M_insert_equal(__x); } 00477 00478 #if __cplusplus >= 201103L 00479 iterator 00480 insert(value_type&& __x) 00481 { return _M_t._M_insert_equal(std::move(__x)); } 00482 #endif 00483 00484 /** 00485 * @brief Inserts an element into the %multiset. 00486 * @param __position An iterator that serves as a hint as to where the 00487 * element should be inserted. 00488 * @param __x Element to be inserted. 00489 * @return An iterator that points to the inserted element. 00490 * 00491 * This function inserts an element into the %multiset. Contrary 00492 * to a std::set the %multiset does not rely on unique keys and thus 00493 * multiple copies of the same element can be inserted. 00494 * 00495 * Note that the first parameter is only a hint and can potentially 00496 * improve the performance of the insertion process. A bad hint would 00497 * cause no gains in efficiency. 00498 * 00499 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00500 * for more on @a hinting. 00501 * 00502 * Insertion requires logarithmic time (if the hint is not taken). 00503 */ 00504 iterator 00505 insert(const_iterator __position, const value_type& __x) 00506 { return _M_t._M_insert_equal_(__position, __x); } 00507 00508 #if __cplusplus >= 201103L 00509 iterator 00510 insert(const_iterator __position, value_type&& __x) 00511 { return _M_t._M_insert_equal_(__position, std::move(__x)); } 00512 #endif 00513 00514 /** 00515 * @brief A template function that tries to insert a range of elements. 00516 * @param __first Iterator pointing to the start of the range to be 00517 * inserted. 00518 * @param __last Iterator pointing to the end of the range. 00519 * 00520 * Complexity similar to that of the range constructor. 00521 */ 00522 template<typename _InputIterator> 00523 void 00524 insert(_InputIterator __first, _InputIterator __last) 00525 { _M_t._M_insert_equal(__first, __last); } 00526 00527 #if __cplusplus >= 201103L 00528 /** 00529 * @brief Attempts to insert a list of elements into the %multiset. 00530 * @param __l A std::initializer_list<value_type> of elements 00531 * to be inserted. 00532 * 00533 * Complexity similar to that of the range constructor. 00534 */ 00535 void 00536 insert(initializer_list<value_type> __l) 00537 { this->insert(__l.begin(), __l.end()); } 00538 #endif 00539 00540 #if __cplusplus >= 201103L 00541 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00542 // DR 130. Associative erase should return an iterator. 00543 /** 00544 * @brief Erases an element from a %multiset. 00545 * @param __position An iterator pointing to the element to be erased. 00546 * @return An iterator pointing to the element immediately following 00547 * @a position prior to the element being erased. If no such 00548 * element exists, end() is returned. 00549 * 00550 * This function erases an element, pointed to by the given iterator, 00551 * from a %multiset. Note that this function only erases the element, 00552 * and that if the element is itself a pointer, the pointed-to memory is 00553 * not touched in any way. Managing the pointer is the user's 00554 * responsibility. 00555 */ 00556 _GLIBCXX_ABI_TAG_CXX11 00557 iterator 00558 erase(const_iterator __position) 00559 { return _M_t.erase(__position); } 00560 #else 00561 /** 00562 * @brief Erases an element from a %multiset. 00563 * @param __position An iterator pointing to the element to be erased. 00564 * 00565 * This function erases an element, pointed to by the given iterator, 00566 * from a %multiset. Note that this function only erases the element, 00567 * and that if the element is itself a pointer, the pointed-to memory is 00568 * not touched in any way. Managing the pointer is the user's 00569 * responsibility. 00570 */ 00571 void 00572 erase(iterator __position) 00573 { _M_t.erase(__position); } 00574 #endif 00575 00576 /** 00577 * @brief Erases elements according to the provided key. 00578 * @param __x Key of element to be erased. 00579 * @return The number of elements erased. 00580 * 00581 * This function erases all elements located by the given key from a 00582 * %multiset. 00583 * Note that this function only erases the element, and that if 00584 * the element is itself a pointer, the pointed-to memory is not touched 00585 * in any way. Managing the pointer is the user's responsibility. 00586 */ 00587 size_type 00588 erase(const key_type& __x) 00589 { return _M_t.erase(__x); } 00590 00591 #if __cplusplus >= 201103L 00592 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00593 // DR 130. Associative erase should return an iterator. 00594 /** 00595 * @brief Erases a [first,last) range of elements from a %multiset. 00596 * @param __first Iterator pointing to the start of the range to be 00597 * erased. 00598 * @param __last Iterator pointing to the end of the range to 00599 * be erased. 00600 * @return The iterator @a last. 00601 * 00602 * This function erases a sequence of elements from a %multiset. 00603 * Note that this function only erases the elements, and that if 00604 * the elements themselves are pointers, the pointed-to memory is not 00605 * touched in any way. Managing the pointer is the user's 00606 * responsibility. 00607 */ 00608 _GLIBCXX_ABI_TAG_CXX11 00609 iterator 00610 erase(const_iterator __first, const_iterator __last) 00611 { return _M_t.erase(__first, __last); } 00612 #else 00613 /** 00614 * @brief Erases a [first,last) range of elements from a %multiset. 00615 * @param first Iterator pointing to the start of the range to be 00616 * erased. 00617 * @param last Iterator pointing to the end of the range to be erased. 00618 * 00619 * This function erases a sequence of elements from a %multiset. 00620 * Note that this function only erases the elements, and that if 00621 * the elements themselves are pointers, the pointed-to memory is not 00622 * touched in any way. Managing the pointer is the user's 00623 * responsibility. 00624 */ 00625 void 00626 erase(iterator __first, iterator __last) 00627 { _M_t.erase(__first, __last); } 00628 #endif 00629 00630 /** 00631 * Erases all elements in a %multiset. Note that this function only 00632 * erases the elements, and that if the elements themselves are pointers, 00633 * the pointed-to memory is not touched in any way. Managing the pointer 00634 * is the user's responsibility. 00635 */ 00636 void 00637 clear() _GLIBCXX_NOEXCEPT 00638 { _M_t.clear(); } 00639 00640 // multiset operations: 00641 00642 //@{ 00643 /** 00644 * @brief Finds the number of elements with given key. 00645 * @param __x Key of elements to be located. 00646 * @return Number of elements with specified key. 00647 */ 00648 size_type 00649 count(const key_type& __x) const 00650 { return _M_t.count(__x); } 00651 00652 #if __cplusplus > 201103L 00653 template<typename _Kt> 00654 auto 00655 count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 00656 { return _M_t._M_count_tr(__x); } 00657 #endif 00658 //@} 00659 00660 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00661 // 214. set::find() missing const overload 00662 //@{ 00663 /** 00664 * @brief Tries to locate an element in a %set. 00665 * @param __x Element to be located. 00666 * @return Iterator pointing to sought-after element, or end() if not 00667 * found. 00668 * 00669 * This function takes a key and tries to locate the element with which 00670 * the key matches. If successful the function returns an iterator 00671 * pointing to the sought after element. If unsuccessful it returns the 00672 * past-the-end ( @c end() ) iterator. 00673 */ 00674 iterator 00675 find(const key_type& __x) 00676 { return _M_t.find(__x); } 00677 00678 const_iterator 00679 find(const key_type& __x) const 00680 { return _M_t.find(__x); } 00681 00682 #if __cplusplus > 201103L 00683 template<typename _Kt> 00684 auto 00685 find(const _Kt& __x) 00686 -> decltype(iterator{_M_t._M_find_tr(__x)}) 00687 { return iterator{_M_t._M_find_tr(__x)}; } 00688 00689 template<typename _Kt> 00690 auto 00691 find(const _Kt& __x) const 00692 -> decltype(const_iterator{_M_t._M_find_tr(__x)}) 00693 { return const_iterator{_M_t._M_find_tr(__x)}; } 00694 #endif 00695 //@} 00696 00697 //@{ 00698 /** 00699 * @brief Finds the beginning of a subsequence matching given key. 00700 * @param __x Key to be located. 00701 * @return Iterator pointing to first element equal to or greater 00702 * than key, or end(). 00703 * 00704 * This function returns the first element of a subsequence of elements 00705 * that matches the given key. If unsuccessful it returns an iterator 00706 * pointing to the first element that has a greater value than given key 00707 * or end() if no such element exists. 00708 */ 00709 iterator 00710 lower_bound(const key_type& __x) 00711 { return _M_t.lower_bound(__x); } 00712 00713 const_iterator 00714 lower_bound(const key_type& __x) const 00715 { return _M_t.lower_bound(__x); } 00716 00717 #if __cplusplus > 201103L 00718 template<typename _Kt> 00719 auto 00720 lower_bound(const _Kt& __x) 00721 -> decltype(_M_t._M_lower_bound_tr(__x)) 00722 { return _M_t._M_lower_bound_tr(__x); } 00723 00724 template<typename _Kt> 00725 auto 00726 lower_bound(const _Kt& __x) const 00727 -> decltype(_M_t._M_lower_bound_tr(__x)) 00728 { return _M_t._M_lower_bound_tr(__x); } 00729 #endif 00730 //@} 00731 00732 //@{ 00733 /** 00734 * @brief Finds the end of a subsequence matching given key. 00735 * @param __x Key to be located. 00736 * @return Iterator pointing to the first element 00737 * greater than key, or end(). 00738 */ 00739 iterator 00740 upper_bound(const key_type& __x) 00741 { return _M_t.upper_bound(__x); } 00742 00743 const_iterator 00744 upper_bound(const key_type& __x) const 00745 { return _M_t.upper_bound(__x); } 00746 00747 #if __cplusplus > 201103L 00748 template<typename _Kt> 00749 auto 00750 upper_bound(const _Kt& __x) 00751 -> decltype(_M_t._M_upper_bound_tr(__x)) 00752 { return _M_t._M_upper_bound_tr(__x); } 00753 00754 template<typename _Kt> 00755 auto 00756 upper_bound(const _Kt& __x) const 00757 -> decltype(_M_t._M_upper_bound_tr(__x)) 00758 { return _M_t._M_upper_bound_tr(__x); } 00759 #endif 00760 //@} 00761 00762 //@{ 00763 /** 00764 * @brief Finds a subsequence matching given key. 00765 * @param __x Key to be located. 00766 * @return Pair of iterators that possibly points to the subsequence 00767 * matching given key. 00768 * 00769 * This function is equivalent to 00770 * @code 00771 * std::make_pair(c.lower_bound(val), 00772 * c.upper_bound(val)) 00773 * @endcode 00774 * (but is faster than making the calls separately). 00775 * 00776 * This function probably only makes sense for multisets. 00777 */ 00778 std::pair<iterator, iterator> 00779 equal_range(const key_type& __x) 00780 { return _M_t.equal_range(__x); } 00781 00782 std::pair<const_iterator, const_iterator> 00783 equal_range(const key_type& __x) const 00784 { return _M_t.equal_range(__x); } 00785 00786 #if __cplusplus > 201103L 00787 template<typename _Kt> 00788 auto 00789 equal_range(const _Kt& __x) 00790 -> decltype(_M_t._M_equal_range_tr(__x)) 00791 { return _M_t._M_equal_range_tr(__x); } 00792 00793 template<typename _Kt> 00794 auto 00795 equal_range(const _Kt& __x) const 00796 -> decltype(_M_t._M_equal_range_tr(__x)) 00797 { return _M_t._M_equal_range_tr(__x); } 00798 #endif 00799 //@} 00800 00801 template<typename _K1, typename _C1, typename _A1> 00802 friend bool 00803 operator==(const multiset<_K1, _C1, _A1>&, 00804 const multiset<_K1, _C1, _A1>&); 00805 00806 template<typename _K1, typename _C1, typename _A1> 00807 friend bool 00808 operator< (const multiset<_K1, _C1, _A1>&, 00809 const multiset<_K1, _C1, _A1>&); 00810 }; 00811 00812 /** 00813 * @brief Multiset equality comparison. 00814 * @param __x A %multiset. 00815 * @param __y A %multiset of the same type as @a __x. 00816 * @return True iff the size and elements of the multisets are equal. 00817 * 00818 * This is an equivalence relation. It is linear in the size of the 00819 * multisets. 00820 * Multisets are considered equivalent if their sizes are equal, and if 00821 * corresponding elements compare equal. 00822 */ 00823 template<typename _Key, typename _Compare, typename _Alloc> 00824 inline bool 00825 operator==(const multiset<_Key, _Compare, _Alloc>& __x, 00826 const multiset<_Key, _Compare, _Alloc>& __y) 00827 { return __x._M_t == __y._M_t; } 00828 00829 /** 00830 * @brief Multiset ordering relation. 00831 * @param __x A %multiset. 00832 * @param __y A %multiset of the same type as @a __x. 00833 * @return True iff @a __x is lexicographically less than @a __y. 00834 * 00835 * This is a total ordering relation. It is linear in the size of the 00836 * sets. The elements must be comparable with @c <. 00837 * 00838 * See std::lexicographical_compare() for how the determination is made. 00839 */ 00840 template<typename _Key, typename _Compare, typename _Alloc> 00841 inline bool 00842 operator<(const multiset<_Key, _Compare, _Alloc>& __x, 00843 const multiset<_Key, _Compare, _Alloc>& __y) 00844 { return __x._M_t < __y._M_t; } 00845 00846 /// Returns !(x == y). 00847 template<typename _Key, typename _Compare, typename _Alloc> 00848 inline bool 00849 operator!=(const multiset<_Key, _Compare, _Alloc>& __x, 00850 const multiset<_Key, _Compare, _Alloc>& __y) 00851 { return !(__x == __y); } 00852 00853 /// Returns y < x. 00854 template<typename _Key, typename _Compare, typename _Alloc> 00855 inline bool 00856 operator>(const multiset<_Key,_Compare,_Alloc>& __x, 00857 const multiset<_Key,_Compare,_Alloc>& __y) 00858 { return __y < __x; } 00859 00860 /// Returns !(y < x) 00861 template<typename _Key, typename _Compare, typename _Alloc> 00862 inline bool 00863 operator<=(const multiset<_Key, _Compare, _Alloc>& __x, 00864 const multiset<_Key, _Compare, _Alloc>& __y) 00865 { return !(__y < __x); } 00866 00867 /// Returns !(x < y) 00868 template<typename _Key, typename _Compare, typename _Alloc> 00869 inline bool 00870 operator>=(const multiset<_Key, _Compare, _Alloc>& __x, 00871 const multiset<_Key, _Compare, _Alloc>& __y) 00872 { return !(__x < __y); } 00873 00874 /// See std::multiset::swap(). 00875 template<typename _Key, typename _Compare, typename _Alloc> 00876 inline void 00877 swap(multiset<_Key, _Compare, _Alloc>& __x, 00878 multiset<_Key, _Compare, _Alloc>& __y) 00879 { __x.swap(__y); } 00880 00881 _GLIBCXX_END_NAMESPACE_CONTAINER 00882 } // namespace std 00883 00884 #endif /* _STL_MULTISET_H */