197403Sobrien// Multimap implementation -*- C++ -*- 297403Sobrien 3169691Skan// Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. 497403Sobrien// 597403Sobrien// This file is part of the GNU ISO C++ Library. This library is free 697403Sobrien// software; you can redistribute it and/or modify it under the 797403Sobrien// terms of the GNU General Public License as published by the 897403Sobrien// Free Software Foundation; either version 2, or (at your option) 997403Sobrien// any later version. 1097403Sobrien 1197403Sobrien// This library is distributed in the hope that it will be useful, 1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of 1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1497403Sobrien// GNU General Public License for more details. 1597403Sobrien 1697403Sobrien// You should have received a copy of the GNU General Public License along 1797403Sobrien// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 1997403Sobrien// USA. 2097403Sobrien 2197403Sobrien// As a special exception, you may use this file as part of a free software 2297403Sobrien// library without restriction. Specifically, if other files instantiate 2397403Sobrien// templates or use macros or inline functions from this file, or you compile 2497403Sobrien// this file and link it with other files to produce an executable, this 2597403Sobrien// file does not by itself cause the resulting executable to be covered by 2697403Sobrien// the GNU General Public License. This exception does not however 2797403Sobrien// invalidate any other reasons why the executable file might be covered by 2897403Sobrien// the GNU General Public License. 2997403Sobrien 3097403Sobrien/* 3197403Sobrien * 3297403Sobrien * Copyright (c) 1994 3397403Sobrien * Hewlett-Packard Company 3497403Sobrien * 3597403Sobrien * Permission to use, copy, modify, distribute and sell this software 3697403Sobrien * and its documentation for any purpose is hereby granted without fee, 3797403Sobrien * provided that the above copyright notice appear in all copies and 3897403Sobrien * that both that copyright notice and this permission notice appear 3997403Sobrien * in supporting documentation. Hewlett-Packard Company makes no 4097403Sobrien * representations about the suitability of this software for any 4197403Sobrien * purpose. It is provided "as is" without express or implied warranty. 4297403Sobrien * 4397403Sobrien * 4497403Sobrien * Copyright (c) 1996,1997 4597403Sobrien * Silicon Graphics Computer Systems, Inc. 4697403Sobrien * 4797403Sobrien * Permission to use, copy, modify, distribute and sell this software 4897403Sobrien * and its documentation for any purpose is hereby granted without fee, 4997403Sobrien * provided that the above copyright notice appear in all copies and 5097403Sobrien * that both that copyright notice and this permission notice appear 5197403Sobrien * in supporting documentation. Silicon Graphics makes no 5297403Sobrien * representations about the suitability of this software for any 5397403Sobrien * purpose. It is provided "as is" without express or implied warranty. 5497403Sobrien */ 5597403Sobrien 5697403Sobrien/** @file stl_multimap.h 5797403Sobrien * This is an internal header file, included by other library headers. 5897403Sobrien * You should not attempt to use it directly. 5997403Sobrien */ 6097403Sobrien 61132720Skan#ifndef _MULTIMAP_H 62132720Skan#define _MULTIMAP_H 1 6397403Sobrien 6497403Sobrien#include <bits/concept_check.h> 6597403Sobrien 66169691Skan_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) 67132720Skan 6897403Sobrien /** 69117397Skan * @brief A standard container made up of (key,value) pairs, which can be 70117397Skan * retrieved based on a key, in logarithmic time. 7197403Sobrien * 72117397Skan * @ingroup Containers 73117397Skan * @ingroup Assoc_containers 7497403Sobrien * 75117397Skan * Meets the requirements of a <a href="tables.html#65">container</a>, a 76117397Skan * <a href="tables.html#66">reversible container</a>, and an 77117397Skan * <a href="tables.html#69">associative container</a> (using equivalent 78117397Skan * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type 79117397Skan * is T, and the value_type is std::pair<const Key,T>. 8097403Sobrien * 81117397Skan * Multimaps support bidirectional iterators. 8297403Sobrien * 83117397Skan * @if maint 84117397Skan * The private tree data is declared exactly the same way for map and 85117397Skan * multimap; the distinction is made entirely in how the tree functions are 86117397Skan * called (*_unique versus *_equal, same as the standard). 87117397Skan * @endif 8897403Sobrien */ 89169691Skan template <typename _Key, typename _Tp, 90169691Skan typename _Compare = std::less<_Key>, 91169691Skan typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 92117397Skan class multimap 93132720Skan { 94169691Skan public: 95169691Skan typedef _Key key_type; 96169691Skan typedef _Tp mapped_type; 97169691Skan typedef std::pair<const _Key, _Tp> value_type; 98169691Skan typedef _Compare key_compare; 99169691Skan typedef _Alloc allocator_type; 100169691Skan 101169691Skan private: 102132720Skan // concept requirements 103169691Skan typedef typename _Alloc::value_type _Alloc_value_type; 104132720Skan __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 105132720Skan __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 106132720Skan _BinaryFunctionConcept) 107169691Skan __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) 108132720Skan 109132720Skan public: 110132720Skan class value_compare 111169691Skan : public std::binary_function<value_type, value_type, bool> 112117397Skan { 113169691Skan friend class multimap<_Key, _Tp, _Compare, _Alloc>; 114117397Skan protected: 115132720Skan _Compare comp; 116132720Skan 117132720Skan value_compare(_Compare __c) 118132720Skan : comp(__c) { } 119132720Skan 120117397Skan public: 121132720Skan bool operator()(const value_type& __x, const value_type& __y) const 122132720Skan { return comp(__x.first, __y.first); } 123132720Skan }; 124132720Skan 125132720Skan private: 126132720Skan /// @if maint This turns a red-black tree into a [multi]map. @endif 127169691Skan typedef typename _Alloc::template rebind<value_type>::other 128169691Skan _Pair_alloc_type; 129169691Skan 130169691Skan typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, 131169691Skan key_compare, _Pair_alloc_type> _Rep_type; 132132720Skan /// @if maint The actual tree structure. @endif 133132720Skan _Rep_type _M_t; 134132720Skan 135132720Skan public: 136132720Skan // many of these are specified differently in ISO, but the following are 137132720Skan // "functionally equivalent" 138169691Skan typedef typename _Pair_alloc_type::pointer pointer; 139169691Skan typedef typename _Pair_alloc_type::const_pointer const_pointer; 140169691Skan typedef typename _Pair_alloc_type::reference reference; 141169691Skan typedef typename _Pair_alloc_type::const_reference const_reference; 142132720Skan typedef typename _Rep_type::iterator iterator; 143132720Skan typedef typename _Rep_type::const_iterator const_iterator; 144132720Skan typedef typename _Rep_type::size_type size_type; 145132720Skan typedef typename _Rep_type::difference_type difference_type; 146132720Skan typedef typename _Rep_type::reverse_iterator reverse_iterator; 147132720Skan typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 148132720Skan 149132720Skan // [23.3.2] construct/copy/destroy 150132720Skan // (get_allocator() is also listed in this section) 151132720Skan /** 152132720Skan * @brief Default constructor creates no elements. 153132720Skan */ 154132720Skan multimap() 155236829Spfg : _M_t() { } 156132720Skan 157132720Skan // for some reason this was made a separate function 158132720Skan /** 159132720Skan * @brief Default constructor creates no elements. 160132720Skan */ 161132720Skan explicit 162132720Skan multimap(const _Compare& __comp, 163132720Skan const allocator_type& __a = allocator_type()) 164117397Skan : _M_t(__comp, __a) { } 165132720Skan 166132720Skan /** 167132720Skan * @brief %Multimap copy constructor. 168132720Skan * @param x A %multimap of identical element and allocator types. 169132720Skan * 170132720Skan * The newly-created %multimap uses a copy of the allocation object used 171132720Skan * by @a x. 172132720Skan */ 173132720Skan multimap(const multimap& __x) 174117397Skan : _M_t(__x._M_t) { } 175132720Skan 176132720Skan /** 177132720Skan * @brief Builds a %multimap from a range. 178132720Skan * @param first An input iterator. 179132720Skan * @param last An input iterator. 180132720Skan * 181132720Skan * Create a %multimap consisting of copies of the elements from 182132720Skan * [first,last). This is linear in N if the range is already sorted, 183132720Skan * and NlogN otherwise (where N is distance(first,last)). 184132720Skan */ 185132720Skan template <typename _InputIterator> 186132720Skan multimap(_InputIterator __first, _InputIterator __last) 187236829Spfg : _M_t() 188265220Smarius { _M_t._M_insert_equal(__first, __last); } 189132720Skan 190132720Skan /** 191132720Skan * @brief Builds a %multimap from a range. 192132720Skan * @param first An input iterator. 193132720Skan * @param last An input iterator. 194132720Skan * @param comp A comparison functor. 195132720Skan * @param a An allocator object. 196132720Skan * 197132720Skan * Create a %multimap consisting of copies of the elements from 198132720Skan * [first,last). This is linear in N if the range is already sorted, 199132720Skan * and NlogN otherwise (where N is distance(first,last)). 200132720Skan */ 201132720Skan template <typename _InputIterator> 202132720Skan multimap(_InputIterator __first, _InputIterator __last, 203132720Skan const _Compare& __comp, 204132720Skan const allocator_type& __a = allocator_type()) 205117397Skan : _M_t(__comp, __a) 206169691Skan { _M_t._M_insert_equal(__first, __last); } 207132720Skan 208132720Skan // FIXME There is no dtor declared, but we should have something generated 209132720Skan // by Doxygen. I don't know what tags to add to this paragraph to make 210132720Skan // that happen: 211132720Skan /** 212132720Skan * The dtor only erases the elements, and note that if the elements 213132720Skan * themselves are pointers, the pointed-to memory is not touched in any 214132720Skan * way. Managing the pointer is the user's responsibilty. 215132720Skan */ 216132720Skan 217132720Skan /** 218132720Skan * @brief %Multimap assignment operator. 219132720Skan * @param x A %multimap of identical element and allocator types. 220132720Skan * 221132720Skan * All the elements of @a x are copied, but unlike the copy constructor, 222132720Skan * the allocator object is not copied. 223132720Skan */ 224132720Skan multimap& 225132720Skan operator=(const multimap& __x) 226132720Skan { 227132720Skan _M_t = __x._M_t; 228132720Skan return *this; 229132720Skan } 230132720Skan 231132720Skan /// Get a copy of the memory allocation object. 232132720Skan allocator_type 233132720Skan get_allocator() const 234132720Skan { return _M_t.get_allocator(); } 235132720Skan 236132720Skan // iterators 237132720Skan /** 238132720Skan * Returns a read/write iterator that points to the first pair in the 239132720Skan * %multimap. Iteration is done in ascending order according to the 240132720Skan * keys. 241132720Skan */ 242132720Skan iterator 243132720Skan begin() 244132720Skan { return _M_t.begin(); } 245132720Skan 246132720Skan /** 247132720Skan * Returns a read-only (constant) iterator that points to the first pair 248132720Skan * in the %multimap. Iteration is done in ascending order according to 249132720Skan * the keys. 250132720Skan */ 251132720Skan const_iterator 252132720Skan begin() const 253132720Skan { return _M_t.begin(); } 254132720Skan 255132720Skan /** 256132720Skan * Returns a read/write iterator that points one past the last pair in 257132720Skan * the %multimap. Iteration is done in ascending order according to the 258132720Skan * keys. 259132720Skan */ 260132720Skan iterator 261132720Skan end() 262132720Skan { return _M_t.end(); } 263132720Skan 264132720Skan /** 265132720Skan * Returns a read-only (constant) iterator that points one past the last 266132720Skan * pair in the %multimap. Iteration is done in ascending order according 267132720Skan * to the keys. 268132720Skan */ 269132720Skan const_iterator 270132720Skan end() const 271132720Skan { return _M_t.end(); } 272132720Skan 273132720Skan /** 274132720Skan * Returns a read/write reverse iterator that points to the last pair in 275132720Skan * the %multimap. Iteration is done in descending order according to the 276132720Skan * keys. 277132720Skan */ 278132720Skan reverse_iterator 279132720Skan rbegin() 280132720Skan { return _M_t.rbegin(); } 281132720Skan 282132720Skan /** 283132720Skan * Returns a read-only (constant) reverse iterator that points to the 284132720Skan * last pair in the %multimap. Iteration is done in descending order 285132720Skan * according to the keys. 286132720Skan */ 287132720Skan const_reverse_iterator 288132720Skan rbegin() const 289132720Skan { return _M_t.rbegin(); } 290132720Skan 291132720Skan /** 292132720Skan * Returns a read/write reverse iterator that points to one before the 293132720Skan * first pair in the %multimap. Iteration is done in descending order 294132720Skan * according to the keys. 295132720Skan */ 296132720Skan reverse_iterator 297132720Skan rend() 298132720Skan { return _M_t.rend(); } 299132720Skan 300132720Skan /** 301132720Skan * Returns a read-only (constant) reverse iterator that points to one 302132720Skan * before the first pair in the %multimap. Iteration is done in 303132720Skan * descending order according to the keys. 304132720Skan */ 305132720Skan const_reverse_iterator 306132720Skan rend() const 307132720Skan { return _M_t.rend(); } 308132720Skan 309132720Skan // capacity 310132720Skan /** Returns true if the %multimap is empty. */ 311132720Skan bool 312132720Skan empty() const 313132720Skan { return _M_t.empty(); } 314132720Skan 315132720Skan /** Returns the size of the %multimap. */ 316132720Skan size_type 317132720Skan size() const 318132720Skan { return _M_t.size(); } 319132720Skan 320132720Skan /** Returns the maximum size of the %multimap. */ 321132720Skan size_type 322132720Skan max_size() const 323132720Skan { return _M_t.max_size(); } 324132720Skan 325132720Skan // modifiers 326132720Skan /** 327132720Skan * @brief Inserts a std::pair into the %multimap. 328132720Skan * @param x Pair to be inserted (see std::make_pair for easy creation 329132720Skan * of pairs). 330132720Skan * @return An iterator that points to the inserted (key,value) pair. 331132720Skan * 332132720Skan * This function inserts a (key, value) pair into the %multimap. 333132720Skan * Contrary to a std::map the %multimap does not rely on unique keys and 334132720Skan * thus multiple pairs with the same key can be inserted. 335132720Skan * 336132720Skan * Insertion requires logarithmic time. 337132720Skan */ 338132720Skan iterator 339132720Skan insert(const value_type& __x) 340169691Skan { return _M_t._M_insert_equal(__x); } 341132720Skan 342132720Skan /** 343132720Skan * @brief Inserts a std::pair into the %multimap. 344132720Skan * @param position An iterator that serves as a hint as to where the 345132720Skan * pair should be inserted. 346132720Skan * @param x Pair to be inserted (see std::make_pair for easy creation 347132720Skan * of pairs). 348132720Skan * @return An iterator that points to the inserted (key,value) pair. 349132720Skan * 350132720Skan * This function inserts a (key, value) pair into the %multimap. 351132720Skan * Contrary to a std::map the %multimap does not rely on unique keys and 352132720Skan * thus multiple pairs with the same key can be inserted. 353132720Skan * Note that the first parameter is only a hint and can potentially 354132720Skan * improve the performance of the insertion process. A bad hint would 355132720Skan * cause no gains in efficiency. 356132720Skan * 357132720Skan * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 358132720Skan * for more on "hinting". 359132720Skan * 360132720Skan * Insertion requires logarithmic time (if the hint is not taken). 361132720Skan */ 362132720Skan iterator 363132720Skan insert(iterator __position, const value_type& __x) 364169691Skan { return _M_t._M_insert_equal(__position, __x); } 365132720Skan 366132720Skan /** 367132720Skan * @brief A template function that attemps to insert a range of elements. 368132720Skan * @param first Iterator pointing to the start of the range to be 369132720Skan * inserted. 370132720Skan * @param last Iterator pointing to the end of the range. 371132720Skan * 372132720Skan * Complexity similar to that of the range constructor. 373132720Skan */ 374132720Skan template <typename _InputIterator> 375132720Skan void 376132720Skan insert(_InputIterator __first, _InputIterator __last) 377169691Skan { _M_t._M_insert_equal(__first, __last); } 378132720Skan 379132720Skan /** 380132720Skan * @brief Erases an element from a %multimap. 381132720Skan * @param position An iterator pointing to the element to be erased. 382132720Skan * 383132720Skan * This function erases an element, pointed to by the given iterator, 384132720Skan * from a %multimap. Note that this function only erases the element, 385132720Skan * and that if the element is itself a pointer, the pointed-to memory is 386132720Skan * not touched in any way. Managing the pointer is the user's 387132720Skan * responsibilty. 388132720Skan */ 389117397Skan void 390132720Skan erase(iterator __position) 391132720Skan { _M_t.erase(__position); } 392132720Skan 393132720Skan /** 394132720Skan * @brief Erases elements according to the provided key. 395132720Skan * @param x Key of element to be erased. 396132720Skan * @return The number of elements erased. 397132720Skan * 398132720Skan * This function erases all elements located by the given key from a 399132720Skan * %multimap. 400132720Skan * Note that this function only erases the element, and that if 401132720Skan * the element is itself a pointer, the pointed-to memory is not touched 402132720Skan * in any way. Managing the pointer is the user's responsibilty. 403132720Skan */ 404132720Skan size_type 405132720Skan erase(const key_type& __x) 406132720Skan { return _M_t.erase(__x); } 407132720Skan 408132720Skan /** 409132720Skan * @brief Erases a [first,last) range of elements from a %multimap. 410132720Skan * @param first Iterator pointing to the start of the range to be 411132720Skan * erased. 412132720Skan * @param last Iterator pointing to the end of the range to be erased. 413132720Skan * 414132720Skan * This function erases a sequence of elements from a %multimap. 415132720Skan * Note that this function only erases the elements, and that if 416132720Skan * the elements themselves are pointers, the pointed-to memory is not 417132720Skan * touched in any way. Managing the pointer is the user's responsibilty. 418132720Skan */ 419132720Skan void 420132720Skan erase(iterator __first, iterator __last) 421132720Skan { _M_t.erase(__first, __last); } 422132720Skan 423132720Skan /** 424132720Skan * @brief Swaps data with another %multimap. 425132720Skan * @param x A %multimap of the same element and allocator types. 426132720Skan * 427132720Skan * This exchanges the elements between two multimaps in constant time. 428132720Skan * (It is only swapping a pointer, an integer, and an instance of 429132720Skan * the @c Compare type (which itself is often stateless and empty), so it 430132720Skan * should be quite fast.) 431132720Skan * Note that the global std::swap() function is specialized such that 432132720Skan * std::swap(m1,m2) will feed to this function. 433132720Skan */ 434132720Skan void 435132720Skan swap(multimap& __x) 436132720Skan { _M_t.swap(__x._M_t); } 437132720Skan 438132720Skan /** 439132720Skan * Erases all elements in a %multimap. Note that this function only 440132720Skan * erases the elements, and that if the elements themselves are pointers, 441132720Skan * the pointed-to memory is not touched in any way. Managing the pointer 442132720Skan * is the user's responsibilty. 443132720Skan */ 444132720Skan void 445132720Skan clear() 446132720Skan { _M_t.clear(); } 447132720Skan 448132720Skan // observers 449132720Skan /** 450132720Skan * Returns the key comparison object out of which the %multimap 451132720Skan * was constructed. 452132720Skan */ 453132720Skan key_compare 454132720Skan key_comp() const 455132720Skan { return _M_t.key_comp(); } 456132720Skan 457132720Skan /** 458132720Skan * Returns a value comparison object, built from the key comparison 459132720Skan * object out of which the %multimap was constructed. 460132720Skan */ 461132720Skan value_compare 462132720Skan value_comp() const 463132720Skan { return value_compare(_M_t.key_comp()); } 464132720Skan 465132720Skan // multimap operations 466132720Skan /** 467132720Skan * @brief Tries to locate an element in a %multimap. 468132720Skan * @param x Key of (key, value) pair to be located. 469132720Skan * @return Iterator pointing to sought-after element, 470132720Skan * or end() if not found. 471132720Skan * 472132720Skan * This function takes a key and tries to locate the element with which 473132720Skan * the key matches. If successful the function returns an iterator 474132720Skan * pointing to the sought after %pair. If unsuccessful it returns the 475132720Skan * past-the-end ( @c end() ) iterator. 476132720Skan */ 477132720Skan iterator 478132720Skan find(const key_type& __x) 479132720Skan { return _M_t.find(__x); } 480132720Skan 481132720Skan /** 482132720Skan * @brief Tries to locate an element in a %multimap. 483132720Skan * @param x Key of (key, value) pair to be located. 484132720Skan * @return Read-only (constant) iterator pointing to sought-after 485132720Skan * element, or end() if not found. 486132720Skan * 487132720Skan * This function takes a key and tries to locate the element with which 488132720Skan * the key matches. If successful the function returns a constant 489132720Skan * iterator pointing to the sought after %pair. If unsuccessful it 490132720Skan * returns the past-the-end ( @c end() ) iterator. 491132720Skan */ 492132720Skan const_iterator 493132720Skan find(const key_type& __x) const 494132720Skan { return _M_t.find(__x); } 495132720Skan 496132720Skan /** 497132720Skan * @brief Finds the number of elements with given key. 498132720Skan * @param x Key of (key, value) pairs to be located. 499132720Skan * @return Number of elements with specified key. 500132720Skan */ 501132720Skan size_type 502132720Skan count(const key_type& __x) const 503132720Skan { return _M_t.count(__x); } 504132720Skan 505132720Skan /** 506132720Skan * @brief Finds the beginning of a subsequence matching given key. 507132720Skan * @param x Key of (key, value) pair to be located. 508132720Skan * @return Iterator pointing to first element equal to or greater 509132720Skan * than key, or end(). 510132720Skan * 511132720Skan * This function returns the first element of a subsequence of elements 512132720Skan * that matches the given key. If unsuccessful it returns an iterator 513132720Skan * pointing to the first element that has a greater value than given key 514132720Skan * or end() if no such element exists. 515132720Skan */ 516132720Skan iterator 517132720Skan lower_bound(const key_type& __x) 518132720Skan { return _M_t.lower_bound(__x); } 519132720Skan 520132720Skan /** 521132720Skan * @brief Finds the beginning of a subsequence matching given key. 522132720Skan * @param x Key of (key, value) pair to be located. 523132720Skan * @return Read-only (constant) iterator pointing to first element 524132720Skan * equal to or greater than key, or end(). 525132720Skan * 526132720Skan * This function returns the first element of a subsequence of elements 527132720Skan * that matches the given key. If unsuccessful the iterator will point 528132720Skan * to the next greatest element or, if no such greater element exists, to 529132720Skan * end(). 530132720Skan */ 531132720Skan const_iterator 532132720Skan lower_bound(const key_type& __x) const 533132720Skan { return _M_t.lower_bound(__x); } 534132720Skan 535132720Skan /** 536132720Skan * @brief Finds the end of a subsequence matching given key. 537132720Skan * @param x Key of (key, value) pair to be located. 538132720Skan * @return Iterator pointing to the first element 539132720Skan * greater than key, or end(). 540132720Skan */ 541132720Skan iterator 542132720Skan upper_bound(const key_type& __x) 543132720Skan { return _M_t.upper_bound(__x); } 544132720Skan 545132720Skan /** 546132720Skan * @brief Finds the end of a subsequence matching given key. 547132720Skan * @param x Key of (key, value) pair to be located. 548132720Skan * @return Read-only (constant) iterator pointing to first iterator 549132720Skan * greater than key, or end(). 550132720Skan */ 551132720Skan const_iterator 552132720Skan upper_bound(const key_type& __x) const 553132720Skan { return _M_t.upper_bound(__x); } 554132720Skan 555132720Skan /** 556132720Skan * @brief Finds a subsequence matching given key. 557132720Skan * @param x Key of (key, value) pairs to be located. 558132720Skan * @return Pair of iterators that possibly points to the subsequence 559132720Skan * matching given key. 560132720Skan * 561132720Skan * This function is equivalent to 562132720Skan * @code 563132720Skan * std::make_pair(c.lower_bound(val), 564132720Skan * c.upper_bound(val)) 565132720Skan * @endcode 566132720Skan * (but is faster than making the calls separately). 567132720Skan */ 568169691Skan std::pair<iterator, iterator> 569132720Skan equal_range(const key_type& __x) 570132720Skan { return _M_t.equal_range(__x); } 571132720Skan 572132720Skan /** 573132720Skan * @brief Finds a subsequence matching given key. 574132720Skan * @param x Key of (key, value) pairs to be located. 575132720Skan * @return Pair of read-only (constant) iterators that possibly points 576132720Skan * to the subsequence matching given key. 577132720Skan * 578132720Skan * This function is equivalent to 579132720Skan * @code 580132720Skan * std::make_pair(c.lower_bound(val), 581132720Skan * c.upper_bound(val)) 582132720Skan * @endcode 583132720Skan * (but is faster than making the calls separately). 584132720Skan */ 585169691Skan std::pair<const_iterator, const_iterator> 586132720Skan equal_range(const key_type& __x) const 587132720Skan { return _M_t.equal_range(__x); } 588132720Skan 589132720Skan template <typename _K1, typename _T1, typename _C1, typename _A1> 590132720Skan friend bool 591169691Skan operator== (const multimap<_K1, _T1, _C1, _A1>&, 592169691Skan const multimap<_K1, _T1, _C1, _A1>&); 593132720Skan 594132720Skan template <typename _K1, typename _T1, typename _C1, typename _A1> 595132720Skan friend bool 596169691Skan operator< (const multimap<_K1, _T1, _C1, _A1>&, 597169691Skan const multimap<_K1, _T1, _C1, _A1>&); 598117397Skan }; 599132720Skan 60097403Sobrien /** 601117397Skan * @brief Multimap equality comparison. 602117397Skan * @param x A %multimap. 603117397Skan * @param y A %multimap of the same type as @a x. 604117397Skan * @return True iff the size and elements of the maps are equal. 60597403Sobrien * 606117397Skan * This is an equivalence relation. It is linear in the size of the 607117397Skan * multimaps. Multimaps are considered equivalent if their sizes are equal, 608117397Skan * and if corresponding elements compare equal. 60997403Sobrien */ 610117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 611117397Skan inline bool 612169691Skan operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 613169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 614132720Skan { return __x._M_t == __y._M_t; } 615132720Skan 61697403Sobrien /** 617117397Skan * @brief Multimap ordering relation. 618117397Skan * @param x A %multimap. 619117397Skan * @param y A %multimap of the same type as @a x. 620132720Skan * @return True iff @a x is lexicographically less than @a y. 62197403Sobrien * 622117397Skan * This is a total ordering relation. It is linear in the size of the 623117397Skan * multimaps. The elements must be comparable with @c <. 62497403Sobrien * 625132720Skan * See std::lexicographical_compare() for how the determination is made. 62697403Sobrien */ 627117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 628117397Skan inline bool 629169691Skan operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 630169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 631117397Skan { return __x._M_t < __y._M_t; } 632132720Skan 633117397Skan /// Based on operator== 634117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 635117397Skan inline bool 636169691Skan operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 637169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 638117397Skan { return !(__x == __y); } 639132720Skan 640117397Skan /// Based on operator< 641117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 642117397Skan inline bool 643169691Skan operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 644169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 645117397Skan { return __y < __x; } 646132720Skan 647117397Skan /// Based on operator< 648117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 649117397Skan inline bool 650169691Skan operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 651169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 652117397Skan { return !(__y < __x); } 653132720Skan 654117397Skan /// Based on operator< 655117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 656117397Skan inline bool 657169691Skan operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 658169691Skan const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 659117397Skan { return !(__x < __y); } 660132720Skan 661117397Skan /// See std::multimap::swap(). 662117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 663117397Skan inline void 664169691Skan swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, 665169691Skan multimap<_Key, _Tp, _Compare, _Alloc>& __y) 666117397Skan { __x.swap(__y); } 66797403Sobrien 668169691Skan_GLIBCXX_END_NESTED_NAMESPACE 669169691Skan 670132720Skan#endif /* _MULTIMAP_H */ 671