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