|
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 : _M_t() { } 00142 00143 /** 00144 * @brief Creates a %multiset with no elements. 00145 * @param __comp Comparator to use. 00146 * @param __a An allocator object. 00147 */ 00148 explicit 00149 multiset(const _Compare& __comp, 00150 const allocator_type& __a = allocator_type()) 00151 : _M_t(__comp, _Key_alloc_type(__a)) { } 00152 00153 /** 00154 * @brief Builds a %multiset from a range. 00155 * @param __first An input iterator. 00156 * @param __last An input iterator. 00157 * 00158 * Create a %multiset consisting of copies of the elements from 00159 * [first,last). This is linear in N if the range is already sorted, 00160 * and NlogN otherwise (where N is distance(__first,__last)). 00161 */ 00162 template<typename _InputIterator> 00163 multiset(_InputIterator __first, _InputIterator __last) 00164 : _M_t() 00165 { _M_t._M_insert_equal(__first, __last); } 00166 00167 /** 00168 * @brief Builds a %multiset from a range. 00169 * @param __first An input iterator. 00170 * @param __last An input iterator. 00171 * @param __comp A comparison functor. 00172 * @param __a An allocator object. 00173 * 00174 * Create a %multiset consisting of copies of the elements from 00175 * [__first,__last). This is linear in N if the range is already sorted, 00176 * and NlogN otherwise (where N is distance(__first,__last)). 00177 */ 00178 template<typename _InputIterator> 00179 multiset(_InputIterator __first, _InputIterator __last, 00180 const _Compare& __comp, 00181 const allocator_type& __a = allocator_type()) 00182 : _M_t(__comp, _Key_alloc_type(__a)) 00183 { _M_t._M_insert_equal(__first, __last); } 00184 00185 /** 00186 * @brief %Multiset copy constructor. 00187 * @param __x A %multiset of identical element and allocator types. 00188 * 00189 * The newly-created %multiset uses a copy of the allocation object used 00190 * by @a __x. 00191 */ 00192 multiset(const multiset& __x) 00193 : _M_t(__x._M_t) { } 00194 00195 #if __cplusplus >= 201103L 00196 /** 00197 * @brief %Multiset move constructor. 00198 * @param __x A %multiset of identical element and allocator types. 00199 * 00200 * The newly-created %multiset contains the exact contents of @a __x. 00201 * The contents of @a __x are a valid, but unspecified %multiset. 00202 */ 00203 multiset(multiset&& __x) 00204 noexcept(is_nothrow_copy_constructible<_Compare>::value) 00205 : _M_t(std::move(__x._M_t)) { } 00206 00207 /** 00208 * @brief Builds a %multiset from an initializer_list. 00209 * @param __l An initializer_list. 00210 * @param __comp A comparison functor. 00211 * @param __a An allocator object. 00212 * 00213 * Create a %multiset consisting of copies of the elements from 00214 * the list. This is linear in N if the list is already sorted, 00215 * and NlogN otherwise (where N is @a __l.size()). 00216 */ 00217 multiset(initializer_list<value_type> __l, 00218 const _Compare& __comp = _Compare(), 00219 const allocator_type& __a = allocator_type()) 00220 : _M_t(__comp, _Key_alloc_type(__a)) 00221 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00222 00223 /// Allocator-extended default constructor. 00224 explicit 00225 multiset(const allocator_type& __a) 00226 : _M_t(_Compare(), _Key_alloc_type(__a)) { } 00227 00228 /// Allocator-extended copy constructor. 00229 multiset(const multiset& __m, const allocator_type& __a) 00230 : _M_t(__m._M_t, _Key_alloc_type(__a)) { } 00231 00232 /// Allocator-extended move constructor. 00233 multiset(multiset&& __m, const allocator_type& __a) 00234 noexcept(is_nothrow_copy_constructible<_Compare>::value 00235 && _Alloc_traits::_S_always_equal()) 00236 : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { } 00237 00238 /// Allocator-extended initialier-list constructor. 00239 multiset(initializer_list<value_type> __l, const allocator_type& __a) 00240 : _M_t(_Compare(), _Key_alloc_type(__a)) 00241 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00242 00243 /// Allocator-extended range constructor. 00244 template<typename _InputIterator> 00245 multiset(_InputIterator __first, _InputIterator __last, 00246 const allocator_type& __a) 00247 : _M_t(_Compare(), _Key_alloc_type(__a)) 00248 { _M_t._M_insert_equal(__first, __last); } 00249 #endif 00250 00251 /** 00252 * @brief %Multiset assignment operator. 00253 * @param __x A %multiset of identical element and allocator types. 00254 * 00255 * All the elements of @a __x are copied, but unlike the copy 00256 * constructor, the allocator object is not copied. 00257 */ 00258 multiset& 00259 operator=(const multiset& __x) 00260 { 00261 _M_t = __x._M_t; 00262 return *this; 00263 } 00264 00265 #if __cplusplus >= 201103L 00266 /// Move assignment operator. 00267 multiset& 00268 operator=(multiset&&) = default; 00269 00270 /** 00271 * @brief %Multiset list assignment operator. 00272 * @param __l An initializer_list. 00273 * 00274 * This function fills a %multiset with copies of the elements in the 00275 * initializer list @a __l. 00276 * 00277 * Note that the assignment completely changes the %multiset and 00278 * that the resulting %multiset's size is the same as the number 00279 * of elements assigned. Old data may be lost. 00280 */ 00281 multiset& 00282 operator=(initializer_list<value_type> __l) 00283 { 00284 _M_t._M_assign_equal(__l.begin(), __l.end()); 00285 return *this; 00286 } 00287 #endif 00288 00289 // accessors: 00290 00291 /// Returns the comparison object. 00292 key_compare 00293 key_comp() const 00294 { return _M_t.key_comp(); } 00295 /// Returns the comparison object. 00296 value_compare 00297 value_comp() const 00298 { return _M_t.key_comp(); } 00299 /// Returns the memory allocation object. 00300 allocator_type 00301 get_allocator() const _GLIBCXX_NOEXCEPT 00302 { return allocator_type(_M_t.get_allocator()); } 00303 00304 /** 00305 * Returns a read-only (constant) iterator that points to the first 00306 * element in the %multiset. Iteration is done in ascending order 00307 * according to the keys. 00308 */ 00309 iterator 00310 begin() const _GLIBCXX_NOEXCEPT 00311 { return _M_t.begin(); } 00312 00313 /** 00314 * Returns a read-only (constant) iterator that points one past the last 00315 * element in the %multiset. Iteration is done in ascending order 00316 * according to the keys. 00317 */ 00318 iterator 00319 end() const _GLIBCXX_NOEXCEPT 00320 { return _M_t.end(); } 00321 00322 /** 00323 * Returns a read-only (constant) reverse iterator that points to the 00324 * last element in the %multiset. Iteration is done in descending order 00325 * according to the keys. 00326 */ 00327 reverse_iterator 00328 rbegin() const _GLIBCXX_NOEXCEPT 00329 { return _M_t.rbegin(); } 00330 00331 /** 00332 * Returns a read-only (constant) reverse iterator that points to the 00333 * last element in the %multiset. Iteration is done in descending order 00334 * according to the keys. 00335 */ 00336 reverse_iterator 00337 rend() const _GLIBCXX_NOEXCEPT 00338 { return _M_t.rend(); } 00339 00340 #if __cplusplus >= 201103L 00341 /** 00342 * Returns a read-only (constant) iterator that points to the first 00343 * element in the %multiset. Iteration is done in ascending order 00344 * according to the keys. 00345 */ 00346 iterator 00347 cbegin() const noexcept 00348 { return _M_t.begin(); } 00349 00350 /** 00351 * Returns a read-only (constant) iterator that points one past the last 00352 * element in the %multiset. Iteration is done in ascending order 00353 * according to the keys. 00354 */ 00355 iterator 00356 cend() const noexcept 00357 { return _M_t.end(); } 00358 00359 /** 00360 * Returns a read-only (constant) reverse iterator that points to the 00361 * last element in the %multiset. Iteration is done in descending order 00362 * according to the keys. 00363 */ 00364 reverse_iterator 00365 crbegin() const noexcept 00366 { return _M_t.rbegin(); } 00367 00368 /** 00369 * Returns a read-only (constant) reverse iterator that points to the 00370 * last element in the %multiset. Iteration is done in descending order 00371 * according to the keys. 00372 */ 00373 reverse_iterator 00374 crend() const noexcept 00375 { return _M_t.rend(); } 00376 #endif 00377 00378 /// Returns true if the %set is empty. 00379 bool 00380 empty() const _GLIBCXX_NOEXCEPT 00381 { return _M_t.empty(); } 00382 00383 /// Returns the size of the %set. 00384 size_type 00385 size() const _GLIBCXX_NOEXCEPT 00386 { return _M_t.size(); } 00387 00388 /// Returns the maximum size of the %set. 00389 size_type 00390 max_size() const _GLIBCXX_NOEXCEPT 00391 { return _M_t.max_size(); } 00392 00393 /** 00394 * @brief Swaps data with another %multiset. 00395 * @param __x A %multiset of the same element and allocator types. 00396 * 00397 * This exchanges the elements between two multisets in constant time. 00398 * (It is only swapping a pointer, an integer, and an instance of the @c 00399 * Compare type (which itself is often stateless and empty), so it should 00400 * be quite fast.) 00401 * Note that the global std::swap() function is specialized such that 00402 * std::swap(s1,s2) will feed to this function. 00403 */ 00404 void 00405 swap(multiset& __x) 00406 #if __cplusplus >= 201103L 00407 noexcept(_Alloc_traits::_S_nothrow_swap()) 00408 #endif 00409 { _M_t.swap(__x._M_t); } 00410 00411 // insert/erase 00412 #if __cplusplus >= 201103L 00413 /** 00414 * @brief Builds and inserts an element into the %multiset. 00415 * @param __args Arguments used to generate the element instance to be 00416 * inserted. 00417 * @return An iterator that points to the inserted element. 00418 * 00419 * This function inserts an element into the %multiset. Contrary 00420 * to a std::set the %multiset does not rely on unique keys and thus 00421 * multiple copies of the same element can be inserted. 00422 * 00423 * Insertion requires logarithmic time. 00424 */ 00425 template<typename... _Args> 00426 iterator 00427 emplace(_Args&&... __args) 00428 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } 00429 00430 /** 00431 * @brief Builds and inserts an element into the %multiset. 00432 * @param __pos An iterator that serves as a hint as to where the 00433 * element should be inserted. 00434 * @param __args Arguments used to generate the element instance to be 00435 * inserted. 00436 * @return An iterator that points to the inserted element. 00437 * 00438 * This function inserts an element into the %multiset. Contrary 00439 * to a std::set the %multiset does not rely on unique keys and thus 00440 * multiple copies of the same element can be inserted. 00441 * 00442 * Note that the first parameter is only a hint and can potentially 00443 * improve the performance of the insertion process. A bad hint would 00444 * cause no gains in efficiency. 00445 * 00446 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00447 * for more on @a hinting. 00448 * 00449 * Insertion requires logarithmic time (if the hint is not taken). 00450 */ 00451 template<typename... _Args> 00452 iterator 00453 emplace_hint(const_iterator __pos, _Args&&... __args) 00454 { 00455 return _M_t._M_emplace_hint_equal(__pos, 00456 std::forward<_Args>(__args)...); 00457 } 00458 #endif 00459 00460 /** 00461 * @brief Inserts an element into the %multiset. 00462 * @param __x Element to be inserted. 00463 * @return An iterator that points to the inserted element. 00464 * 00465 * This function inserts an element into the %multiset. Contrary 00466 * to a std::set the %multiset does not rely on unique keys and thus 00467 * multiple copies of the same element can be inserted. 00468 * 00469 * Insertion requires logarithmic time. 00470 */ 00471 iterator 00472 insert(const value_type& __x) 00473 { return _M_t._M_insert_equal(__x); } 00474 00475 #if __cplusplus >= 201103L 00476 iterator 00477 insert(value_type&& __x) 00478 { return _M_t._M_insert_equal(std::move(__x)); } 00479 #endif 00480 00481 /** 00482 * @brief Inserts an element into the %multiset. 00483 * @param __position An iterator that serves as a hint as to where the 00484 * element should be inserted. 00485 * @param __x Element to be inserted. 00486 * @return An iterator that points to the inserted element. 00487 * 00488 * This function inserts an element into the %multiset. Contrary 00489 * to a std::set the %multiset does not rely on unique keys and thus 00490 * multiple copies of the same element can be inserted. 00491 * 00492 * Note that the first parameter is only a hint and can potentially 00493 * improve the performance of the insertion process. A bad hint would 00494 * cause no gains in efficiency. 00495 * 00496 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00497 * for more on @a hinting. 00498 * 00499 * Insertion requires logarithmic time (if the hint is not taken). 00500 */ 00501 iterator 00502 insert(const_iterator __position, const value_type& __x) 00503 { return _M_t._M_insert_equal_(__position, __x); } 00504 00505 #if __cplusplus >= 201103L 00506 iterator 00507 insert(const_iterator __position, value_type&& __x) 00508 { return _M_t._M_insert_equal_(__position, std::move(__x)); } 00509 #endif 00510 00511 /** 00512 * @brief A template function that tries to insert a range of elements. 00513 * @param __first Iterator pointing to the start of the range to be 00514 * inserted. 00515 * @param __last Iterator pointing to the end of the range. 00516 * 00517 * Complexity similar to that of the range constructor. 00518 */ 00519 template<typename _InputIterator> 00520 void 00521 insert(_InputIterator __first, _InputIterator __last) 00522 { _M_t._M_insert_equal(__first, __last); } 00523 00524 #if __cplusplus >= 201103L 00525 /** 00526 * @brief Attempts to insert a list of elements into the %multiset. 00527 * @param __l A std::initializer_list<value_type> of elements 00528 * to be inserted. 00529 * 00530 * Complexity similar to that of the range constructor. 00531 */ 00532 void 00533 insert(initializer_list<value_type> __l) 00534 { this->insert(__l.begin(), __l.end()); } 00535 #endif 00536 00537 #if __cplusplus >= 201103L 00538 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00539 // DR 130. Associative erase should return an iterator. 00540 /** 00541 * @brief Erases an element from a %multiset. 00542 * @param __position An iterator pointing to the element to be erased. 00543 * @return An iterator pointing to the element immediately following 00544 * @a position prior to the element being erased. If no such 00545 * element exists, end() is returned. 00546 * 00547 * This function erases an element, pointed to by the given iterator, 00548 * from a %multiset. Note that this function only erases the element, 00549 * and that if the element is itself a pointer, the pointed-to memory is 00550 * not touched in any way. Managing the pointer is the user's 00551 * responsibility. 00552 */ 00553 _GLIBCXX_ABI_TAG_CXX11 00554 iterator 00555 erase(const_iterator __position) 00556 { return _M_t.erase(__position); } 00557 #else 00558 /** 00559 * @brief Erases an element from a %multiset. 00560 * @param __position An iterator pointing to the element to be erased. 00561 * 00562 * This function erases an element, pointed to by the given iterator, 00563 * from a %multiset. Note that this function only erases the element, 00564 * and that if the element is itself a pointer, the pointed-to memory is 00565 * not touched in any way. Managing the pointer is the user's 00566 * responsibility. 00567 */ 00568 void 00569 erase(iterator __position) 00570 { _M_t.erase(__position); } 00571 #endif 00572 00573 /** 00574 * @brief Erases elements according to the provided key. 00575 * @param __x Key of element to be erased. 00576 * @return The number of elements erased. 00577 * 00578 * This function erases all elements located by the given key from a 00579 * %multiset. 00580 * Note that this function only erases the element, and that if 00581 * the element is itself a pointer, the pointed-to memory is not touched 00582 * in any way. Managing the pointer is the user's responsibility. 00583 */ 00584 size_type 00585 erase(const key_type& __x) 00586 { return _M_t.erase(__x); } 00587 00588 #if __cplusplus >= 201103L 00589 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00590 // DR 130. Associative erase should return an iterator. 00591 /** 00592 * @brief Erases a [first,last) range of elements from a %multiset. 00593 * @param __first Iterator pointing to the start of the range to be 00594 * erased. 00595 * @param __last Iterator pointing to the end of the range to 00596 * be erased. 00597 * @return The iterator @a last. 00598 * 00599 * This function erases a sequence of elements from a %multiset. 00600 * Note that this function only erases the elements, and that if 00601 * the elements themselves are pointers, the pointed-to memory is not 00602 * touched in any way. Managing the pointer is the user's 00603 * responsibility. 00604 */ 00605 _GLIBCXX_ABI_TAG_CXX11 00606 iterator 00607 erase(const_iterator __first, const_iterator __last) 00608 { return _M_t.erase(__first, __last); } 00609 #else 00610 /** 00611 * @brief Erases a [first,last) range of elements from a %multiset. 00612 * @param first Iterator pointing to the start of the range to be 00613 * erased. 00614 * @param last Iterator pointing to the end of the range to be erased. 00615 * 00616 * This function erases a sequence of elements from a %multiset. 00617 * Note that this function only erases the elements, and that if 00618 * the elements themselves are pointers, the pointed-to memory is not 00619 * touched in any way. Managing the pointer is the user's 00620 * responsibility. 00621 */ 00622 void 00623 erase(iterator __first, iterator __last) 00624 { _M_t.erase(__first, __last); } 00625 #endif 00626 00627 /** 00628 * Erases all elements in a %multiset. Note that this function only 00629 * erases the elements, and that if the elements themselves are pointers, 00630 * the pointed-to memory is not touched in any way. Managing the pointer 00631 * is the user's responsibility. 00632 */ 00633 void 00634 clear() _GLIBCXX_NOEXCEPT 00635 { _M_t.clear(); } 00636 00637 // multiset operations: 00638 00639 //@{ 00640 /** 00641 * @brief Finds the number of elements with given key. 00642 * @param __x Key of elements to be located. 00643 * @return Number of elements with specified key. 00644 */ 00645 size_type 00646 count(const key_type& __x) const 00647 { return _M_t.count(__x); } 00648 00649 #if __cplusplus > 201103L 00650 template<typename _Kt> 00651 auto 00652 count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 00653 { return _M_t._M_count_tr(__x); } 00654 #endif 00655 //@} 00656 00657 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00658 // 214. set::find() missing const overload 00659 //@{ 00660 /** 00661 * @brief Tries to locate an element in a %set. 00662 * @param __x Element to be located. 00663 * @return Iterator pointing to sought-after element, or end() if not 00664 * found. 00665 * 00666 * This function takes a key and tries to locate the element with which 00667 * the key matches. If successful the function returns an iterator 00668 * pointing to the sought after element. If unsuccessful it returns the 00669 * past-the-end ( @c end() ) iterator. 00670 */ 00671 iterator 00672 find(const key_type& __x) 00673 { return _M_t.find(__x); } 00674 00675 const_iterator 00676 find(const key_type& __x) const 00677 { return _M_t.find(__x); } 00678 00679 #if __cplusplus > 201103L 00680 template<typename _Kt> 00681 auto 00682 find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) 00683 { return _M_t._M_find_tr(__x); } 00684 00685 template<typename _Kt> 00686 auto 00687 find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) 00688 { return _M_t._M_find_tr(__x); } 00689 #endif 00690 //@} 00691 00692 //@{ 00693 /** 00694 * @brief Finds the beginning of a subsequence matching given key. 00695 * @param __x Key to be located. 00696 * @return Iterator pointing to first element equal to or greater 00697 * than key, or end(). 00698 * 00699 * This function returns the first element of a subsequence of elements 00700 * that matches the given key. If unsuccessful it returns an iterator 00701 * pointing to the first element that has a greater value than given key 00702 * or end() if no such element exists. 00703 */ 00704 iterator 00705 lower_bound(const key_type& __x) 00706 { return _M_t.lower_bound(__x); } 00707 00708 const_iterator 00709 lower_bound(const key_type& __x) const 00710 { return _M_t.lower_bound(__x); } 00711 00712 #if __cplusplus > 201103L 00713 template<typename _Kt> 00714 auto 00715 lower_bound(const _Kt& __x) 00716 -> decltype(_M_t._M_lower_bound_tr(__x)) 00717 { return _M_t._M_lower_bound_tr(__x); } 00718 00719 template<typename _Kt> 00720 auto 00721 lower_bound(const _Kt& __x) const 00722 -> decltype(_M_t._M_lower_bound_tr(__x)) 00723 { return _M_t._M_lower_bound_tr(__x); } 00724 #endif 00725 //@} 00726 00727 //@{ 00728 /** 00729 * @brief Finds the end of a subsequence matching given key. 00730 * @param __x Key to be located. 00731 * @return Iterator pointing to the first element 00732 * greater than key, or end(). 00733 */ 00734 iterator 00735 upper_bound(const key_type& __x) 00736 { return _M_t.upper_bound(__x); } 00737 00738 const_iterator 00739 upper_bound(const key_type& __x) const 00740 { return _M_t.upper_bound(__x); } 00741 00742 #if __cplusplus > 201103L 00743 template<typename _Kt> 00744 auto 00745 upper_bound(const _Kt& __x) 00746 -> decltype(_M_t._M_upper_bound_tr(__x)) 00747 { return _M_t._M_upper_bound_tr(__x); } 00748 00749 template<typename _Kt> 00750 auto 00751 upper_bound(const _Kt& __x) const 00752 -> decltype(_M_t._M_upper_bound_tr(__x)) 00753 { return _M_t._M_upper_bound_tr(__x); } 00754 #endif 00755 //@} 00756 00757 //@{ 00758 /** 00759 * @brief Finds a subsequence matching given key. 00760 * @param __x Key to be located. 00761 * @return Pair of iterators that possibly points to the subsequence 00762 * matching given key. 00763 * 00764 * This function is equivalent to 00765 * @code 00766 * std::make_pair(c.lower_bound(val), 00767 * c.upper_bound(val)) 00768 * @endcode 00769 * (but is faster than making the calls separately). 00770 * 00771 * This function probably only makes sense for multisets. 00772 */ 00773 std::pair<iterator, iterator> 00774 equal_range(const key_type& __x) 00775 { return _M_t.equal_range(__x); } 00776 00777 std::pair<const_iterator, const_iterator> 00778 equal_range(const key_type& __x) const 00779 { return _M_t.equal_range(__x); } 00780 00781 #if __cplusplus > 201103L 00782 template<typename _Kt> 00783 auto 00784 equal_range(const _Kt& __x) 00785 -> decltype(_M_t._M_equal_range_tr(__x)) 00786 { return _M_t._M_equal_range_tr(__x); } 00787 00788 template<typename _Kt> 00789 auto 00790 equal_range(const _Kt& __x) const 00791 -> decltype(_M_t._M_equal_range_tr(__x)) 00792 { return _M_t._M_equal_range_tr(__x); } 00793 #endif 00794 //@} 00795 00796 template<typename _K1, typename _C1, typename _A1> 00797 friend bool 00798 operator==(const multiset<_K1, _C1, _A1>&, 00799 const multiset<_K1, _C1, _A1>&); 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 00807 /** 00808 * @brief Multiset equality comparison. 00809 * @param __x A %multiset. 00810 * @param __y A %multiset of the same type as @a __x. 00811 * @return True iff the size and elements of the multisets are equal. 00812 * 00813 * This is an equivalence relation. It is linear in the size of the 00814 * multisets. 00815 * Multisets are considered equivalent if their sizes are equal, and if 00816 * corresponding elements compare equal. 00817 */ 00818 template<typename _Key, typename _Compare, typename _Alloc> 00819 inline bool 00820 operator==(const multiset<_Key, _Compare, _Alloc>& __x, 00821 const multiset<_Key, _Compare, _Alloc>& __y) 00822 { return __x._M_t == __y._M_t; } 00823 00824 /** 00825 * @brief Multiset ordering relation. 00826 * @param __x A %multiset. 00827 * @param __y A %multiset of the same type as @a __x. 00828 * @return True iff @a __x is lexicographically less than @a __y. 00829 * 00830 * This is a total ordering relation. It is linear in the size of the 00831 * sets. The elements must be comparable with @c <. 00832 * 00833 * See std::lexicographical_compare() for how the determination is made. 00834 */ 00835 template<typename _Key, typename _Compare, typename _Alloc> 00836 inline bool 00837 operator<(const multiset<_Key, _Compare, _Alloc>& __x, 00838 const multiset<_Key, _Compare, _Alloc>& __y) 00839 { return __x._M_t < __y._M_t; } 00840 00841 /// Returns !(x == y). 00842 template<typename _Key, typename _Compare, typename _Alloc> 00843 inline bool 00844 operator!=(const multiset<_Key, _Compare, _Alloc>& __x, 00845 const multiset<_Key, _Compare, _Alloc>& __y) 00846 { return !(__x == __y); } 00847 00848 /// Returns y < x. 00849 template<typename _Key, typename _Compare, typename _Alloc> 00850 inline bool 00851 operator>(const multiset<_Key,_Compare,_Alloc>& __x, 00852 const multiset<_Key,_Compare,_Alloc>& __y) 00853 { return __y < __x; } 00854 00855 /// Returns !(y < x) 00856 template<typename _Key, typename _Compare, typename _Alloc> 00857 inline bool 00858 operator<=(const multiset<_Key, _Compare, _Alloc>& __x, 00859 const multiset<_Key, _Compare, _Alloc>& __y) 00860 { return !(__y < __x); } 00861 00862 /// Returns !(x < y) 00863 template<typename _Key, typename _Compare, typename _Alloc> 00864 inline bool 00865 operator>=(const multiset<_Key, _Compare, _Alloc>& __x, 00866 const multiset<_Key, _Compare, _Alloc>& __y) 00867 { return !(__x < __y); } 00868 00869 /// See std::multiset::swap(). 00870 template<typename _Key, typename _Compare, typename _Alloc> 00871 inline void 00872 swap(multiset<_Key, _Compare, _Alloc>& __x, 00873 multiset<_Key, _Compare, _Alloc>& __y) 00874 { __x.swap(__y); } 00875 00876 _GLIBCXX_END_NAMESPACE_CONTAINER 00877 } // namespace std 00878 00879 #endif /* _STL_MULTISET_H */