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