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