|
libstdc++
|
00001 // Multimap 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,1997 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_multimap.h 00052 * This is an internal header file, included by other library headers. 00053 * Do not attempt to use it directly. @headername{map} 00054 */ 00055 00056 #ifndef _STL_MULTIMAP_H 00057 #define _STL_MULTIMAP_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 (key,value) pairs, which can be 00070 * retrieved based on a key, in logarithmic time. 00071 * 00072 * @ingroup associative_containers 00073 * 00074 * @tparam _Key Type of key objects. 00075 * @tparam _Tp Type of mapped objects. 00076 * @tparam _Compare Comparison function object type, defaults to less<_Key>. 00077 * @tparam _Alloc Allocator type, defaults to 00078 * allocator<pair<const _Key, _Tp>. 00079 * 00080 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00081 * <a href="tables.html#66">reversible container</a>, and an 00082 * <a href="tables.html#69">associative container</a> (using equivalent 00083 * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type 00084 * is T, and the value_type is std::pair<const Key,T>. 00085 * 00086 * Multimaps support bidirectional iterators. 00087 * 00088 * The private tree data is declared exactly the same way for map and 00089 * multimap; the distinction is made entirely in how the tree functions are 00090 * called (*_unique versus *_equal, same as the standard). 00091 */ 00092 template <typename _Key, typename _Tp, 00093 typename _Compare = std::less<_Key>, 00094 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 00095 class multimap 00096 { 00097 public: 00098 typedef _Key key_type; 00099 typedef _Tp mapped_type; 00100 typedef std::pair<const _Key, _Tp> value_type; 00101 typedef _Compare key_compare; 00102 typedef _Alloc allocator_type; 00103 00104 private: 00105 // concept requirements 00106 typedef typename _Alloc::value_type _Alloc_value_type; 00107 __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 00108 __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 00109 _BinaryFunctionConcept) 00110 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) 00111 00112 public: 00113 class value_compare 00114 : public std::binary_function<value_type, value_type, bool> 00115 { 00116 friend class multimap<_Key, _Tp, _Compare, _Alloc>; 00117 protected: 00118 _Compare comp; 00119 00120 value_compare(_Compare __c) 00121 : comp(__c) { } 00122 00123 public: 00124 bool operator()(const value_type& __x, const value_type& __y) const 00125 { return comp(__x.first, __y.first); } 00126 }; 00127 00128 private: 00129 /// This turns a red-black tree into a [multi]map. 00130 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template 00131 rebind<value_type>::other _Pair_alloc_type; 00132 00133 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, 00134 key_compare, _Pair_alloc_type> _Rep_type; 00135 /// The actual tree structure. 00136 _Rep_type _M_t; 00137 00138 typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; 00139 00140 public: 00141 // many of these are specified differently in ISO, but the following are 00142 // "functionally equivalent" 00143 typedef typename _Alloc_traits::pointer pointer; 00144 typedef typename _Alloc_traits::const_pointer const_pointer; 00145 typedef typename _Alloc_traits::reference reference; 00146 typedef typename _Alloc_traits::const_reference const_reference; 00147 typedef typename _Rep_type::iterator iterator; 00148 typedef typename _Rep_type::const_iterator const_iterator; 00149 typedef typename _Rep_type::size_type size_type; 00150 typedef typename _Rep_type::difference_type difference_type; 00151 typedef typename _Rep_type::reverse_iterator reverse_iterator; 00152 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 00153 00154 // [23.3.2] construct/copy/destroy 00155 // (get_allocator() is also listed in this section) 00156 00157 /** 00158 * @brief Default constructor creates no elements. 00159 */ 00160 multimap() 00161 : _M_t() { } 00162 00163 /** 00164 * @brief Creates a %multimap with no elements. 00165 * @param __comp A comparison object. 00166 * @param __a An allocator object. 00167 */ 00168 explicit 00169 multimap(const _Compare& __comp, 00170 const allocator_type& __a = allocator_type()) 00171 : _M_t(__comp, _Pair_alloc_type(__a)) { } 00172 00173 /** 00174 * @brief %Multimap copy constructor. 00175 * @param __x A %multimap of identical element and allocator types. 00176 * 00177 * The newly-created %multimap uses a copy of the allocation object 00178 * used by @a __x. 00179 */ 00180 multimap(const multimap& __x) 00181 : _M_t(__x._M_t) { } 00182 00183 #if __cplusplus >= 201103L 00184 /** 00185 * @brief %Multimap move constructor. 00186 * @param __x A %multimap of identical element and allocator types. 00187 * 00188 * The newly-created %multimap contains the exact contents of @a __x. 00189 * The contents of @a __x are a valid, but unspecified %multimap. 00190 */ 00191 multimap(multimap&& __x) 00192 noexcept(is_nothrow_copy_constructible<_Compare>::value) 00193 : _M_t(std::move(__x._M_t)) { } 00194 00195 /** 00196 * @brief Builds a %multimap from an initializer_list. 00197 * @param __l An initializer_list. 00198 * @param __comp A comparison functor. 00199 * @param __a An allocator object. 00200 * 00201 * Create a %multimap consisting of copies of the elements from 00202 * the initializer_list. This is linear in N if the list is already 00203 * sorted, and NlogN otherwise (where N is @a __l.size()). 00204 */ 00205 multimap(initializer_list<value_type> __l, 00206 const _Compare& __comp = _Compare(), 00207 const allocator_type& __a = allocator_type()) 00208 : _M_t(__comp, _Pair_alloc_type(__a)) 00209 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00210 00211 /// Allocator-extended default constructor. 00212 explicit 00213 multimap(const allocator_type& __a) 00214 : _M_t(_Compare(), _Pair_alloc_type(__a)) { } 00215 00216 /// Allocator-extended copy constructor. 00217 multimap(const multimap& __m, const allocator_type& __a) 00218 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } 00219 00220 /// Allocator-extended move constructor. 00221 multimap(multimap&& __m, const allocator_type& __a) 00222 noexcept(is_nothrow_copy_constructible<_Compare>::value 00223 && _Alloc_traits::_S_always_equal()) 00224 : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } 00225 00226 /// Allocator-extended initialier-list constructor. 00227 multimap(initializer_list<value_type> __l, const allocator_type& __a) 00228 : _M_t(_Compare(), _Pair_alloc_type(__a)) 00229 { _M_t._M_insert_equal(__l.begin(), __l.end()); } 00230 00231 /// Allocator-extended range constructor. 00232 template<typename _InputIterator> 00233 multimap(_InputIterator __first, _InputIterator __last, 00234 const allocator_type& __a) 00235 : _M_t(_Compare(), _Pair_alloc_type(__a)) 00236 { _M_t._M_insert_equal(__first, __last); } 00237 #endif 00238 00239 /** 00240 * @brief Builds a %multimap from a range. 00241 * @param __first An input iterator. 00242 * @param __last An input iterator. 00243 * 00244 * Create a %multimap consisting of copies of the elements from 00245 * [__first,__last). This is linear in N if the range is already sorted, 00246 * and NlogN otherwise (where N is distance(__first,__last)). 00247 */ 00248 template<typename _InputIterator> 00249 multimap(_InputIterator __first, _InputIterator __last) 00250 : _M_t() 00251 { _M_t._M_insert_equal(__first, __last); } 00252 00253 /** 00254 * @brief Builds a %multimap from a range. 00255 * @param __first An input iterator. 00256 * @param __last An input iterator. 00257 * @param __comp A comparison functor. 00258 * @param __a An allocator object. 00259 * 00260 * Create a %multimap consisting of copies of the elements from 00261 * [__first,__last). This is linear in N if the range is already sorted, 00262 * and NlogN otherwise (where N is distance(__first,__last)). 00263 */ 00264 template<typename _InputIterator> 00265 multimap(_InputIterator __first, _InputIterator __last, 00266 const _Compare& __comp, 00267 const allocator_type& __a = allocator_type()) 00268 : _M_t(__comp, _Pair_alloc_type(__a)) 00269 { _M_t._M_insert_equal(__first, __last); } 00270 00271 // FIXME There is no dtor declared, but we should have something generated 00272 // by Doxygen. I don't know what tags to add to this paragraph to make 00273 // that happen: 00274 /** 00275 * The dtor only erases the elements, and note that if the elements 00276 * themselves are pointers, the pointed-to memory is not touched in any 00277 * way. Managing the pointer is the user's responsibility. 00278 */ 00279 00280 /** 00281 * @brief %Multimap assignment operator. 00282 * @param __x A %multimap of identical element and allocator types. 00283 * 00284 * All the elements of @a __x are copied, but unlike the copy 00285 * constructor, the allocator object is not copied. 00286 */ 00287 multimap& 00288 operator=(const multimap& __x) 00289 { 00290 _M_t = __x._M_t; 00291 return *this; 00292 } 00293 00294 #if __cplusplus >= 201103L 00295 /// Move assignment operator. 00296 multimap& 00297 operator=(multimap&&) = default; 00298 00299 /** 00300 * @brief %Multimap list assignment operator. 00301 * @param __l An initializer_list. 00302 * 00303 * This function fills a %multimap with copies of the elements 00304 * in the initializer list @a __l. 00305 * 00306 * Note that the assignment completely changes the %multimap and 00307 * that the resulting %multimap's size is the same as the number 00308 * of elements assigned. Old data may be lost. 00309 */ 00310 multimap& 00311 operator=(initializer_list<value_type> __l) 00312 { 00313 _M_t._M_assign_equal(__l.begin(), __l.end()); 00314 return *this; 00315 } 00316 #endif 00317 00318 /// Get a copy of the memory allocation object. 00319 allocator_type 00320 get_allocator() const _GLIBCXX_NOEXCEPT 00321 { return allocator_type(_M_t.get_allocator()); } 00322 00323 // iterators 00324 /** 00325 * Returns a read/write iterator that points to the first pair in the 00326 * %multimap. Iteration is done in ascending order according to the 00327 * keys. 00328 */ 00329 iterator 00330 begin() _GLIBCXX_NOEXCEPT 00331 { return _M_t.begin(); } 00332 00333 /** 00334 * Returns a read-only (constant) iterator that points to the first pair 00335 * in the %multimap. Iteration is done in ascending order according to 00336 * the keys. 00337 */ 00338 const_iterator 00339 begin() const _GLIBCXX_NOEXCEPT 00340 { return _M_t.begin(); } 00341 00342 /** 00343 * Returns a read/write iterator that points one past the last pair in 00344 * the %multimap. Iteration is done in ascending order according to the 00345 * keys. 00346 */ 00347 iterator 00348 end() _GLIBCXX_NOEXCEPT 00349 { return _M_t.end(); } 00350 00351 /** 00352 * Returns a read-only (constant) iterator that points one past the last 00353 * pair in the %multimap. Iteration is done in ascending order according 00354 * to the keys. 00355 */ 00356 const_iterator 00357 end() const _GLIBCXX_NOEXCEPT 00358 { return _M_t.end(); } 00359 00360 /** 00361 * Returns a read/write reverse iterator that points to the last pair in 00362 * the %multimap. Iteration is done in descending order according to the 00363 * keys. 00364 */ 00365 reverse_iterator 00366 rbegin() _GLIBCXX_NOEXCEPT 00367 { return _M_t.rbegin(); } 00368 00369 /** 00370 * Returns a read-only (constant) reverse iterator that points to the 00371 * last pair in the %multimap. Iteration is done in descending order 00372 * according to the keys. 00373 */ 00374 const_reverse_iterator 00375 rbegin() const _GLIBCXX_NOEXCEPT 00376 { return _M_t.rbegin(); } 00377 00378 /** 00379 * Returns a read/write reverse iterator that points to one before the 00380 * first pair in the %multimap. Iteration is done in descending order 00381 * according to the keys. 00382 */ 00383 reverse_iterator 00384 rend() _GLIBCXX_NOEXCEPT 00385 { return _M_t.rend(); } 00386 00387 /** 00388 * Returns a read-only (constant) reverse iterator that points to one 00389 * before the first pair in the %multimap. Iteration is done in 00390 * descending order according to the keys. 00391 */ 00392 const_reverse_iterator 00393 rend() const _GLIBCXX_NOEXCEPT 00394 { return _M_t.rend(); } 00395 00396 #if __cplusplus >= 201103L 00397 /** 00398 * Returns a read-only (constant) iterator that points to the first pair 00399 * in the %multimap. Iteration is done in ascending order according to 00400 * the keys. 00401 */ 00402 const_iterator 00403 cbegin() const noexcept 00404 { return _M_t.begin(); } 00405 00406 /** 00407 * Returns a read-only (constant) iterator that points one past the last 00408 * pair in the %multimap. Iteration is done in ascending order according 00409 * to the keys. 00410 */ 00411 const_iterator 00412 cend() const noexcept 00413 { return _M_t.end(); } 00414 00415 /** 00416 * Returns a read-only (constant) reverse iterator that points to the 00417 * last pair in the %multimap. Iteration is done in descending order 00418 * according to the keys. 00419 */ 00420 const_reverse_iterator 00421 crbegin() const noexcept 00422 { return _M_t.rbegin(); } 00423 00424 /** 00425 * Returns a read-only (constant) reverse iterator that points to one 00426 * before the first pair in the %multimap. Iteration is done in 00427 * descending order according to the keys. 00428 */ 00429 const_reverse_iterator 00430 crend() const noexcept 00431 { return _M_t.rend(); } 00432 #endif 00433 00434 // capacity 00435 /** Returns true if the %multimap is empty. */ 00436 bool 00437 empty() const _GLIBCXX_NOEXCEPT 00438 { return _M_t.empty(); } 00439 00440 /** Returns the size of the %multimap. */ 00441 size_type 00442 size() const _GLIBCXX_NOEXCEPT 00443 { return _M_t.size(); } 00444 00445 /** Returns the maximum size of the %multimap. */ 00446 size_type 00447 max_size() const _GLIBCXX_NOEXCEPT 00448 { return _M_t.max_size(); } 00449 00450 // modifiers 00451 #if __cplusplus >= 201103L 00452 /** 00453 * @brief Build and insert a std::pair into the %multimap. 00454 * 00455 * @param __args Arguments used to generate a new pair instance (see 00456 * std::piecewise_contruct for passing arguments to each 00457 * part of the pair constructor). 00458 * 00459 * @return An iterator that points to the inserted (key,value) pair. 00460 * 00461 * This function builds and inserts a (key, value) %pair into the 00462 * %multimap. 00463 * Contrary to a std::map the %multimap does not rely on unique keys and 00464 * thus multiple pairs with the same key can be inserted. 00465 * 00466 * Insertion requires logarithmic time. 00467 */ 00468 template<typename... _Args> 00469 iterator 00470 emplace(_Args&&... __args) 00471 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } 00472 00473 /** 00474 * @brief Builds and inserts a std::pair into the %multimap. 00475 * 00476 * @param __pos An iterator that serves as a hint as to where the pair 00477 * should be inserted. 00478 * @param __args Arguments used to generate a new pair instance (see 00479 * std::piecewise_contruct for passing arguments to each 00480 * part of the pair constructor). 00481 * @return An iterator that points to the inserted (key,value) pair. 00482 * 00483 * This function inserts a (key, value) pair into the %multimap. 00484 * Contrary to a std::map the %multimap does not rely on unique keys and 00485 * thus multiple pairs with the same key can be inserted. 00486 * Note that the first parameter is only a hint and can potentially 00487 * improve the performance of the insertion process. A bad hint would 00488 * cause no gains in efficiency. 00489 * 00490 * For more on @a hinting, see: 00491 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00492 * 00493 * Insertion requires logarithmic time (if the hint is not taken). 00494 */ 00495 template<typename... _Args> 00496 iterator 00497 emplace_hint(const_iterator __pos, _Args&&... __args) 00498 { 00499 return _M_t._M_emplace_hint_equal(__pos, 00500 std::forward<_Args>(__args)...); 00501 } 00502 #endif 00503 00504 /** 00505 * @brief Inserts a std::pair into the %multimap. 00506 * @param __x Pair to be inserted (see std::make_pair for easy creation 00507 * of pairs). 00508 * @return An iterator that points to the inserted (key,value) pair. 00509 * 00510 * This function inserts a (key, value) pair into the %multimap. 00511 * Contrary to a std::map the %multimap does not rely on unique keys and 00512 * thus multiple pairs with the same key can be inserted. 00513 * 00514 * Insertion requires logarithmic time. 00515 */ 00516 iterator 00517 insert(const value_type& __x) 00518 { return _M_t._M_insert_equal(__x); } 00519 00520 #if __cplusplus >= 201103L 00521 template<typename _Pair, typename = typename 00522 std::enable_if<std::is_constructible<value_type, 00523 _Pair&&>::value>::type> 00524 iterator 00525 insert(_Pair&& __x) 00526 { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); } 00527 #endif 00528 00529 /** 00530 * @brief Inserts a std::pair into the %multimap. 00531 * @param __position An iterator that serves as a hint as to where the 00532 * pair should be inserted. 00533 * @param __x Pair to be inserted (see std::make_pair for easy creation 00534 * of pairs). 00535 * @return An iterator that points to the inserted (key,value) pair. 00536 * 00537 * This function inserts a (key, value) pair into the %multimap. 00538 * Contrary to a std::map the %multimap does not rely on unique keys and 00539 * thus multiple pairs with the same key can be inserted. 00540 * Note that the first parameter is only a hint and can potentially 00541 * improve the performance of the insertion process. A bad hint would 00542 * cause no gains in efficiency. 00543 * 00544 * For more on @a hinting, see: 00545 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 00546 * 00547 * Insertion requires logarithmic time (if the hint is not taken). 00548 */ 00549 iterator 00550 #if __cplusplus >= 201103L 00551 insert(const_iterator __position, const value_type& __x) 00552 #else 00553 insert(iterator __position, const value_type& __x) 00554 #endif 00555 { return _M_t._M_insert_equal_(__position, __x); } 00556 00557 #if __cplusplus >= 201103L 00558 template<typename _Pair, typename = typename 00559 std::enable_if<std::is_constructible<value_type, 00560 _Pair&&>::value>::type> 00561 iterator 00562 insert(const_iterator __position, _Pair&& __x) 00563 { return _M_t._M_insert_equal_(__position, 00564 std::forward<_Pair>(__x)); } 00565 #endif 00566 00567 /** 00568 * @brief A template function that attempts to insert a range 00569 * of elements. 00570 * @param __first Iterator pointing to the start of the range to be 00571 * inserted. 00572 * @param __last Iterator pointing to the end of the range. 00573 * 00574 * Complexity similar to that of the range constructor. 00575 */ 00576 template<typename _InputIterator> 00577 void 00578 insert(_InputIterator __first, _InputIterator __last) 00579 { _M_t._M_insert_equal(__first, __last); } 00580 00581 #if __cplusplus >= 201103L 00582 /** 00583 * @brief Attempts to insert a list of std::pairs into the %multimap. 00584 * @param __l A std::initializer_list<value_type> of pairs to be 00585 * inserted. 00586 * 00587 * Complexity similar to that of the range constructor. 00588 */ 00589 void 00590 insert(initializer_list<value_type> __l) 00591 { this->insert(__l.begin(), __l.end()); } 00592 #endif 00593 00594 #if __cplusplus >= 201103L 00595 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00596 // DR 130. Associative erase should return an iterator. 00597 /** 00598 * @brief Erases an element from a %multimap. 00599 * @param __position An iterator pointing to the element to be erased. 00600 * @return An iterator pointing to the element immediately following 00601 * @a position prior to the element being erased. If no such 00602 * element exists, end() is returned. 00603 * 00604 * This function erases an element, pointed to by the given iterator, 00605 * from a %multimap. Note that this function only erases the element, 00606 * and that if the element is itself a pointer, the pointed-to memory is 00607 * not touched in any way. Managing the pointer is the user's 00608 * responsibility. 00609 */ 00610 iterator 00611 erase(const_iterator __position) 00612 { return _M_t.erase(__position); } 00613 00614 // LWG 2059. 00615 _GLIBCXX_ABI_TAG_CXX11 00616 iterator 00617 erase(iterator __position) 00618 { return _M_t.erase(__position); } 00619 #else 00620 /** 00621 * @brief Erases an element from a %multimap. 00622 * @param __position An iterator pointing to the element to be erased. 00623 * 00624 * This function erases an element, pointed to by the given iterator, 00625 * from a %multimap. Note that this function only erases the element, 00626 * and that if the element is itself a pointer, the pointed-to memory is 00627 * not touched in any way. Managing the pointer is the user's 00628 * responsibility. 00629 */ 00630 void 00631 erase(iterator __position) 00632 { _M_t.erase(__position); } 00633 #endif 00634 00635 /** 00636 * @brief Erases elements according to the provided key. 00637 * @param __x Key of element to be erased. 00638 * @return The number of elements erased. 00639 * 00640 * This function erases all elements located by the given key from a 00641 * %multimap. 00642 * Note that this function only erases the element, and that if 00643 * the element is itself a pointer, the pointed-to memory is not touched 00644 * in any way. Managing the pointer is the user's responsibility. 00645 */ 00646 size_type 00647 erase(const key_type& __x) 00648 { return _M_t.erase(__x); } 00649 00650 #if __cplusplus >= 201103L 00651 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00652 // DR 130. Associative erase should return an iterator. 00653 /** 00654 * @brief Erases a [first,last) range of elements from a %multimap. 00655 * @param __first Iterator pointing to the start of the range to be 00656 * erased. 00657 * @param __last Iterator pointing to the end of the range to be 00658 * erased . 00659 * @return The iterator @a __last. 00660 * 00661 * This function erases a sequence of elements from a %multimap. 00662 * Note that this function only erases the elements, and that if 00663 * the elements themselves are pointers, the pointed-to memory is not 00664 * touched in any way. Managing the pointer is the user's 00665 * responsibility. 00666 */ 00667 iterator 00668 erase(const_iterator __first, const_iterator __last) 00669 { return _M_t.erase(__first, __last); } 00670 #else 00671 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00672 // DR 130. Associative erase should return an iterator. 00673 /** 00674 * @brief Erases a [first,last) range of elements from a %multimap. 00675 * @param __first Iterator pointing to the start of the range to be 00676 * erased. 00677 * @param __last Iterator pointing to the end of the range to 00678 * be erased. 00679 * 00680 * This function erases a sequence of elements from a %multimap. 00681 * Note that this function only erases the elements, and that if 00682 * the elements themselves are pointers, the pointed-to memory is not 00683 * touched in any way. Managing the pointer is the user's 00684 * responsibility. 00685 */ 00686 void 00687 erase(iterator __first, iterator __last) 00688 { _M_t.erase(__first, __last); } 00689 #endif 00690 00691 /** 00692 * @brief Swaps data with another %multimap. 00693 * @param __x A %multimap of the same element and allocator types. 00694 * 00695 * This exchanges the elements between two multimaps in constant time. 00696 * (It is only swapping a pointer, an integer, and an instance of 00697 * the @c Compare type (which itself is often stateless and empty), so it 00698 * should be quite fast.) 00699 * Note that the global std::swap() function is specialized such that 00700 * std::swap(m1,m2) will feed to this function. 00701 */ 00702 void 00703 swap(multimap& __x) 00704 #if __cplusplus >= 201103L 00705 noexcept(_Alloc_traits::_S_nothrow_swap()) 00706 #endif 00707 { _M_t.swap(__x._M_t); } 00708 00709 /** 00710 * Erases all elements in a %multimap. Note that this function only 00711 * erases the elements, and that if the elements themselves are pointers, 00712 * the pointed-to memory is not touched in any way. Managing the pointer 00713 * is the user's responsibility. 00714 */ 00715 void 00716 clear() _GLIBCXX_NOEXCEPT 00717 { _M_t.clear(); } 00718 00719 // observers 00720 /** 00721 * Returns the key comparison object out of which the %multimap 00722 * was constructed. 00723 */ 00724 key_compare 00725 key_comp() const 00726 { return _M_t.key_comp(); } 00727 00728 /** 00729 * Returns a value comparison object, built from the key comparison 00730 * object out of which the %multimap was constructed. 00731 */ 00732 value_compare 00733 value_comp() const 00734 { return value_compare(_M_t.key_comp()); } 00735 00736 // multimap operations 00737 00738 //@{ 00739 /** 00740 * @brief Tries to locate an element in a %multimap. 00741 * @param __x Key of (key, value) pair to be located. 00742 * @return Iterator pointing to sought-after element, 00743 * or end() if not found. 00744 * 00745 * This function takes a key and tries to locate the element with which 00746 * the key matches. If successful the function returns an iterator 00747 * pointing to the sought after %pair. If unsuccessful it returns the 00748 * past-the-end ( @c end() ) iterator. 00749 */ 00750 iterator 00751 find(const key_type& __x) 00752 { return _M_t.find(__x); } 00753 00754 #if __cplusplus > 201103L 00755 template<typename _Kt> 00756 auto 00757 find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) 00758 { return _M_t._M_find_tr(__x); } 00759 #endif 00760 //@} 00761 00762 //@{ 00763 /** 00764 * @brief Tries to locate an element in a %multimap. 00765 * @param __x Key of (key, value) pair to be located. 00766 * @return Read-only (constant) iterator pointing to sought-after 00767 * element, or end() if not found. 00768 * 00769 * This function takes a key and tries to locate the element with which 00770 * the key matches. If successful the function returns a constant 00771 * iterator pointing to the sought after %pair. If unsuccessful it 00772 * returns the past-the-end ( @c end() ) iterator. 00773 */ 00774 const_iterator 00775 find(const key_type& __x) const 00776 { return _M_t.find(__x); } 00777 00778 #if __cplusplus > 201103L 00779 template<typename _Kt> 00780 auto 00781 find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) 00782 { return _M_t._M_find_tr(__x); } 00783 #endif 00784 //@} 00785 00786 //@{ 00787 /** 00788 * @brief Finds the number of elements with given key. 00789 * @param __x Key of (key, value) pairs to be located. 00790 * @return Number of elements with specified key. 00791 */ 00792 size_type 00793 count(const key_type& __x) const 00794 { return _M_t.count(__x); } 00795 00796 #if __cplusplus > 201103L 00797 template<typename _Kt> 00798 auto 00799 count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 00800 { return _M_t._M_count_tr(__x); } 00801 #endif 00802 //@} 00803 00804 //@{ 00805 /** 00806 * @brief Finds the beginning of a subsequence matching given key. 00807 * @param __x Key of (key, value) pair to be located. 00808 * @return Iterator pointing to first element equal to or greater 00809 * than key, or end(). 00810 * 00811 * This function returns the first element of a subsequence of elements 00812 * that matches the given key. If unsuccessful it returns an iterator 00813 * pointing to the first element that has a greater value than given key 00814 * or end() if no such element exists. 00815 */ 00816 iterator 00817 lower_bound(const key_type& __x) 00818 { return _M_t.lower_bound(__x); } 00819 00820 #if __cplusplus > 201103L 00821 template<typename _Kt> 00822 auto 00823 lower_bound(const _Kt& __x) 00824 -> decltype(_M_t._M_lower_bound_tr(__x)) 00825 { return _M_t._M_lower_bound_tr(__x); } 00826 #endif 00827 //@} 00828 00829 //@{ 00830 /** 00831 * @brief Finds the beginning of a subsequence matching given key. 00832 * @param __x Key of (key, value) pair to be located. 00833 * @return Read-only (constant) iterator pointing to first element 00834 * equal to or greater than key, or end(). 00835 * 00836 * This function returns the first element of a subsequence of 00837 * elements that matches the given key. If unsuccessful the 00838 * iterator will point to the next greatest element or, if no 00839 * such greater element exists, to end(). 00840 */ 00841 const_iterator 00842 lower_bound(const key_type& __x) const 00843 { return _M_t.lower_bound(__x); } 00844 00845 #if __cplusplus > 201103L 00846 template<typename _Kt> 00847 auto 00848 lower_bound(const _Kt& __x) const 00849 -> decltype(_M_t._M_lower_bound_tr(__x)) 00850 { return _M_t._M_lower_bound_tr(__x); } 00851 #endif 00852 //@} 00853 00854 //@{ 00855 /** 00856 * @brief Finds the end of a subsequence matching given key. 00857 * @param __x Key of (key, value) pair to be located. 00858 * @return Iterator pointing to the first element 00859 * greater than key, or end(). 00860 */ 00861 iterator 00862 upper_bound(const key_type& __x) 00863 { return _M_t.upper_bound(__x); } 00864 00865 #if __cplusplus > 201103L 00866 template<typename _Kt> 00867 auto 00868 upper_bound(const _Kt& __x) 00869 -> decltype(_M_t._M_upper_bound_tr(__x)) 00870 { return _M_t._M_upper_bound_tr(__x); } 00871 #endif 00872 //@} 00873 00874 //@{ 00875 /** 00876 * @brief Finds the end of a subsequence matching given key. 00877 * @param __x Key of (key, value) pair to be located. 00878 * @return Read-only (constant) iterator pointing to first iterator 00879 * greater than key, or end(). 00880 */ 00881 const_iterator 00882 upper_bound(const key_type& __x) const 00883 { return _M_t.upper_bound(__x); } 00884 00885 #if __cplusplus > 201103L 00886 template<typename _Kt> 00887 auto 00888 upper_bound(const _Kt& __x) const 00889 -> decltype(_M_t._M_upper_bound_tr(__x)) 00890 { return _M_t._M_upper_bound_tr(__x); } 00891 #endif 00892 //@} 00893 00894 //@{ 00895 /** 00896 * @brief Finds a subsequence matching given key. 00897 * @param __x Key of (key, value) pairs to be located. 00898 * @return Pair of iterators that possibly points to the subsequence 00899 * matching given key. 00900 * 00901 * This function is equivalent to 00902 * @code 00903 * std::make_pair(c.lower_bound(val), 00904 * c.upper_bound(val)) 00905 * @endcode 00906 * (but is faster than making the calls separately). 00907 */ 00908 std::pair<iterator, iterator> 00909 equal_range(const key_type& __x) 00910 { return _M_t.equal_range(__x); } 00911 00912 #if __cplusplus > 201103L 00913 template<typename _Kt> 00914 auto 00915 equal_range(const _Kt& __x) 00916 -> decltype(_M_t._M_equal_range_tr(__x)) 00917 { return _M_t._M_equal_range_tr(__x); } 00918 #endif 00919 //@} 00920 00921 //@{ 00922 /** 00923 * @brief Finds a subsequence matching given key. 00924 * @param __x Key of (key, value) pairs to be located. 00925 * @return Pair of read-only (constant) iterators that possibly points 00926 * to the subsequence matching given key. 00927 * 00928 * This function is equivalent to 00929 * @code 00930 * std::make_pair(c.lower_bound(val), 00931 * c.upper_bound(val)) 00932 * @endcode 00933 * (but is faster than making the calls separately). 00934 */ 00935 std::pair<const_iterator, const_iterator> 00936 equal_range(const key_type& __x) const 00937 { return _M_t.equal_range(__x); } 00938 00939 #if __cplusplus > 201103L 00940 template<typename _Kt> 00941 auto 00942 equal_range(const _Kt& __x) const 00943 -> decltype(_M_t._M_equal_range_tr(__x)) 00944 { return _M_t._M_equal_range_tr(__x); } 00945 #endif 00946 //@} 00947 00948 template<typename _K1, typename _T1, typename _C1, typename _A1> 00949 friend bool 00950 operator==(const multimap<_K1, _T1, _C1, _A1>&, 00951 const multimap<_K1, _T1, _C1, _A1>&); 00952 00953 template<typename _K1, typename _T1, typename _C1, typename _A1> 00954 friend bool 00955 operator<(const multimap<_K1, _T1, _C1, _A1>&, 00956 const multimap<_K1, _T1, _C1, _A1>&); 00957 }; 00958 00959 /** 00960 * @brief Multimap equality comparison. 00961 * @param __x A %multimap. 00962 * @param __y A %multimap of the same type as @a __x. 00963 * @return True iff the size and elements of the maps are equal. 00964 * 00965 * This is an equivalence relation. It is linear in the size of the 00966 * multimaps. Multimaps are considered equivalent if their sizes are equal, 00967 * and if corresponding elements compare equal. 00968 */ 00969 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 00970 inline bool 00971 operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 00972 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 00973 { return __x._M_t == __y._M_t; } 00974 00975 /** 00976 * @brief Multimap ordering relation. 00977 * @param __x A %multimap. 00978 * @param __y A %multimap of the same type as @a __x. 00979 * @return True iff @a x is lexicographically less than @a y. 00980 * 00981 * This is a total ordering relation. It is linear in the size of the 00982 * multimaps. The elements must be comparable with @c <. 00983 * 00984 * See std::lexicographical_compare() for how the determination is made. 00985 */ 00986 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 00987 inline bool 00988 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 00989 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 00990 { return __x._M_t < __y._M_t; } 00991 00992 /// Based on operator== 00993 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 00994 inline bool 00995 operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 00996 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 00997 { return !(__x == __y); } 00998 00999 /// Based on operator< 01000 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 01001 inline bool 01002 operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 01003 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 01004 { return __y < __x; } 01005 01006 /// Based on operator< 01007 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 01008 inline bool 01009 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 01010 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 01011 { return !(__y < __x); } 01012 01013 /// Based on operator< 01014 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 01015 inline bool 01016 operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 01017 const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 01018 { return !(__x < __y); } 01019 01020 /// See std::multimap::swap(). 01021 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 01022 inline void 01023 swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, 01024 multimap<_Key, _Tp, _Compare, _Alloc>& __y) 01025 { __x.swap(__y); } 01026 01027 _GLIBCXX_END_NAMESPACE_CONTAINER 01028 } // namespace std 01029 01030 #endif /* _STL_MULTIMAP_H */