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