155714Skris// Multimap implementation -*- C++ -*- 255714Skris 355714Skris// Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. 455714Skris// 555714Skris// This file is part of the GNU ISO C++ Library. This library is free 655714Skris// software; you can redistribute it and/or modify it under the 755714Skris// terms of the GNU General Public License as published by the 8280304Sjkim// Free Software Foundation; either version 2, or (at your option) 955714Skris// any later version. 1055714Skris 1155714Skris// This library is distributed in the hope that it will be useful, 1255714Skris// but WITHOUT ANY WARRANTY; without even the implied warranty of 1355714Skris// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1455714Skris// GNU General Public License for more details. 15280304Sjkim 1655714Skris// You should have received a copy of the GNU General Public License along 1755714Skris// with this library; see the file COPYING. If not, write to the Free 1855714Skris// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 1955714Skris// USA. 2055714Skris 2155714Skris// As a special exception, you may use this file as part of a free software 22280304Sjkim// library without restriction. Specifically, if other files instantiate 2355714Skris// templates or use macros or inline functions from this file, or you compile 2455714Skris// this file and link it with other files to produce an executable, this 2555714Skris// file does not by itself cause the resulting executable to be covered by 2655714Skris// the GNU General Public License. This exception does not however 2755714Skris// invalidate any other reasons why the executable file might be covered by 2855714Skris// the GNU General Public License. 2955714Skris 3055714Skris/* 3155714Skris * 3255714Skris * Copyright (c) 1994 3355714Skris * Hewlett-Packard Company 3455714Skris * 3555714Skris * Permission to use, copy, modify, distribute and sell this software 3655714Skris * and its documentation for any purpose is hereby granted without fee, 37280304Sjkim * provided that the above copyright notice appear in all copies and 3855714Skris * that both that copyright notice and this permission notice appear 3955714Skris * in supporting documentation. Hewlett-Packard Company makes no 40280304Sjkim * representations about the suitability of this software for any 4155714Skris * purpose. It is provided "as is" without express or implied warranty. 4255714Skris * 4355714Skris * 4455714Skris * Copyright (c) 1996,1997 4555714Skris * Silicon Graphics Computer Systems, Inc. 4655714Skris * 4755714Skris * Permission to use, copy, modify, distribute and sell this software 4855714Skris * and its documentation for any purpose is hereby granted without fee, 4955714Skris * provided that the above copyright notice appear in all copies and 5055714Skris * that both that copyright notice and this permission notice appear 5155714Skris * in supporting documentation. Silicon Graphics makes no 52280304Sjkim * representations about the suitability of this software for any 5355714Skris * purpose. It is provided "as is" without express or implied warranty. 5455714Skris */ 5555714Skris 5655714Skris/** @file stl_multimap.h 5755714Skris * This is an internal header file, included by other library headers. 5855714Skris * You should not attempt to use it directly. 5955714Skris */ 6055714Skris 6155714Skris#ifndef _MULTIMAP_H 6255714Skris#define _MULTIMAP_H 1 6355714Skris 6459191Skris#include <bits/concept_check.h> 65160814Ssimon 6655714Skris_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) 6755714Skris 68280304Sjkim /** 6955714Skris * @brief A standard container made up of (key,value) pairs, which can be 7055714Skris * retrieved based on a key, in logarithmic time. 71280304Sjkim * 72280304Sjkim * @ingroup Containers 73280304Sjkim * @ingroup Assoc_containers 74100928Snectar * 75280304Sjkim * Meets the requirements of a <a href="tables.html#65">container</a>, a 76100928Snectar * <a href="tables.html#66">reversible container</a>, and an 77280304Sjkim * <a href="tables.html#69">associative container</a> (using equivalent 78280304Sjkim * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type 79280304Sjkim * is T, and the value_type is std::pair<const Key,T>. 80280304Sjkim * 81280304Sjkim * Multimaps support bidirectional iterators. 82280304Sjkim * 83280304Sjkim * @if maint 84280304Sjkim * The private tree data is declared exactly the same way for map and 85280304Sjkim * multimap; the distinction is made entirely in how the tree functions are 86280304Sjkim * called (*_unique versus *_equal, same as the standard). 87280304Sjkim * @endif 88280304Sjkim */ 89100928Snectar template <typename _Key, typename _Tp, 90280304Sjkim typename _Compare = std::less<_Key>, 91100928Snectar typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 92280304Sjkim class multimap 93280304Sjkim { 94127128Snectar public: 95280304Sjkim typedef _Key key_type; 96280304Sjkim typedef _Tp mapped_type; 97280304Sjkim typedef std::pair<const _Key, _Tp> value_type; 98280304Sjkim typedef _Compare key_compare; 99280304Sjkim typedef _Alloc allocator_type; 100280304Sjkim 101280304Sjkim private: 102280304Sjkim // concept requirements 103100928Snectar typedef typename _Alloc::value_type _Alloc_value_type; 104160814Ssimon __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 105280304Sjkim __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 106280304Sjkim _BinaryFunctionConcept) 107280304Sjkim __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) 108280304Sjkim 109280304Sjkim public: 110280304Sjkim class value_compare 111280304Sjkim : public std::binary_function<value_type, value_type, bool> 112160814Ssimon { 113280304Sjkim friend class multimap<_Key, _Tp, _Compare, _Alloc>; 114280304Sjkim protected: 115280304Sjkim _Compare comp; 116280304Sjkim 117280304Sjkim value_compare(_Compare __c) 118160814Ssimon : comp(__c) { } 119280304Sjkim 120280304Sjkim public: 121280304Sjkim bool operator()(const value_type& __x, const value_type& __y) const 122280304Sjkim { return comp(__x.first, __y.first); } 123280304Sjkim }; 124280304Sjkim 125280304Sjkim private: 126280304Sjkim /// @if maint This turns a red-black tree into a [multi]map. @endif 127160814Ssimon typedef typename _Alloc::template rebind<value_type>::other 128280304Sjkim _Pair_alloc_type; 129160814Ssimon 130280304Sjkim typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, 131280304Sjkim key_compare, _Pair_alloc_type> _Rep_type; 132280304Sjkim /// @if maint The actual tree structure. @endif 133280304Sjkim _Rep_type _M_t; 134160814Ssimon 135280304Sjkim public: 136160814Ssimon // many of these are specified differently in ISO, but the following are 137238405Sjkim // "functionally equivalent" 138280304Sjkim typedef typename _Pair_alloc_type::pointer pointer; 139280304Sjkim typedef typename _Pair_alloc_type::const_pointer const_pointer; 140280304Sjkim typedef typename _Pair_alloc_type::reference reference; 141280304Sjkim typedef typename _Pair_alloc_type::const_reference const_reference; 142280304Sjkim typedef typename _Rep_type::iterator iterator; 143280304Sjkim typedef typename _Rep_type::const_iterator const_iterator; 144280304Sjkim typedef typename _Rep_type::size_type size_type; 145238405Sjkim typedef typename _Rep_type::difference_type difference_type; 146280304Sjkim typedef typename _Rep_type::reverse_iterator reverse_iterator; 147238405Sjkim typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 148280304Sjkim 149280304Sjkim // [23.3.2] construct/copy/destroy 150238405Sjkim // (get_allocator() is also listed in this section) 151280304Sjkim /** 152280304Sjkim * @brief Default constructor creates no elements. 153280304Sjkim */ 154238405Sjkim multimap() 155280304Sjkim : _M_t() { } 156280304Sjkim 157238405Sjkim // for some reason this was made a separate function 158280304Sjkim /** 159280304Sjkim * @brief Default constructor creates no elements. 160280304Sjkim */ 161280304Sjkim explicit 162280304Sjkim multimap(const _Compare& __comp, 163238405Sjkim const allocator_type& __a = allocator_type()) 164280304Sjkim : _M_t(__comp, __a) { } 165280304Sjkim 166238405Sjkim /** 167280304Sjkim * @brief %Multimap copy constructor. 168238405Sjkim * @param x A %multimap of identical element and allocator types. 169280304Sjkim * 170280304Sjkim * The newly-created %multimap uses a copy of the allocation object used 171280304Sjkim * by @a x. 172280304Sjkim */ 173238405Sjkim multimap(const multimap& __x) 174280304Sjkim : _M_t(__x._M_t) { } 175280304Sjkim 176238405Sjkim /** 177280304Sjkim * @brief Builds a %multimap from a range. 178280304Sjkim * @param first An input iterator. 179238405Sjkim * @param last An input iterator. 180280304Sjkim * 181238405Sjkim * Create a %multimap consisting of copies of the elements from 182280304Sjkim * [first,last). This is linear in N if the range is already sorted, 183280304Sjkim * and NlogN otherwise (where N is distance(first,last)). 184280304Sjkim */ 185280304Sjkim template <typename _InputIterator> 186280304Sjkim multimap(_InputIterator __first, _InputIterator __last) 187280304Sjkim : _M_t() 188280304Sjkim { _M_t._M_insert_unique(__first, __last); } 189280304Sjkim 190238405Sjkim /** 191280304Sjkim * @brief Builds a %multimap from a range. 192238405Sjkim * @param first An input iterator. 193238405Sjkim * @param last An input iterator. 194280304Sjkim * @param comp A comparison functor. 195280304Sjkim * @param a An allocator object. 196280304Sjkim * 197280304Sjkim * Create a %multimap consisting of copies of the elements from 198280304Sjkim * [first,last). This is linear in N if the range is already sorted, 199238405Sjkim * and NlogN otherwise (where N is distance(first,last)). 200280304Sjkim */ 201238405Sjkim template <typename _InputIterator> 202280304Sjkim multimap(_InputIterator __first, _InputIterator __last, 203280304Sjkim const _Compare& __comp, 204280304Sjkim const allocator_type& __a = allocator_type()) 205238405Sjkim : _M_t(__comp, __a) 206280304Sjkim { _M_t._M_insert_equal(__first, __last); } 207280304Sjkim 208238405Sjkim // FIXME There is no dtor declared, but we should have something generated 209280304Sjkim // by Doxygen. I don't know what tags to add to this paragraph to make 210280304Sjkim // that happen: 211280304Sjkim /** 212280304Sjkim * The dtor only erases the elements, and note that if the elements 213280304Sjkim * themselves are pointers, the pointed-to memory is not touched in any 214238405Sjkim * way. Managing the pointer is the user's responsibilty. 215280304Sjkim */ 216280304Sjkim 217280304Sjkim /** 218238405Sjkim * @brief %Multimap assignment operator. 219280304Sjkim * @param x A %multimap of identical element and allocator types. 220238405Sjkim * 221280304Sjkim * All the elements of @a x are copied, but unlike the copy constructor, 222280304Sjkim * the allocator object is not copied. 223280304Sjkim */ 224280304Sjkim multimap& 225238405Sjkim operator=(const multimap& __x) 226280304Sjkim { 227280304Sjkim _M_t = __x._M_t; 228280304Sjkim return *this; 229280304Sjkim } 230280304Sjkim 231280304Sjkim /// Get a copy of the memory allocation object. 232238405Sjkim allocator_type 233280304Sjkim get_allocator() const 234238405Sjkim { return _M_t.get_allocator(); } 235280304Sjkim 236280304Sjkim // iterators 237280304Sjkim /** 238280304Sjkim * Returns a read/write iterator that points to the first pair in the 239238405Sjkim * %multimap. Iteration is done in ascending order according to the 240280304Sjkim * keys. 241280304Sjkim */ 242238405Sjkim iterator 243280304Sjkim begin() 244280304Sjkim { return _M_t.begin(); } 245280304Sjkim 246280304Sjkim /** 247280304Sjkim * Returns a read-only (constant) iterator that points to the first pair 248238405Sjkim * in the %multimap. Iteration is done in ascending order according to 249280304Sjkim * the keys. 250280304Sjkim */ 251238405Sjkim const_iterator 25255714Skris begin() const 253280304Sjkim { return _M_t.begin(); } 254280304Sjkim 255280304Sjkim /** 256280304Sjkim * Returns a read/write iterator that points one past the last pair in 257280304Sjkim * the %multimap. Iteration is done in ascending order according to the 258280304Sjkim * keys. 259280304Sjkim */ 260280304Sjkim iterator 261280304Sjkim end() 262280304Sjkim { return _M_t.end(); } 26355714Skris 264280304Sjkim /** 265280304Sjkim * Returns a read-only (constant) iterator that points one past the last 266280304Sjkim * pair in the %multimap. Iteration is done in ascending order according 267280304Sjkim * to the keys. 268280304Sjkim */ 269280304Sjkim const_iterator 270280304Sjkim end() const 271280304Sjkim { return _M_t.end(); } 272280304Sjkim 273280304Sjkim /** 274280304Sjkim * Returns a read/write reverse iterator that points to the last pair in 275280304Sjkim * the %multimap. Iteration is done in descending order according to the 276280304Sjkim * keys. 277280304Sjkim */ 278280304Sjkim reverse_iterator 279280304Sjkim rbegin() 280280304Sjkim { return _M_t.rbegin(); } 281280304Sjkim 282280266Sdelphij /** 283280304Sjkim * Returns a read-only (constant) reverse iterator that points to the 284280304Sjkim * last pair in the %multimap. Iteration is done in descending order 28555714Skris * according to the keys. 286280304Sjkim */ 287280304Sjkim const_reverse_iterator 288280304Sjkim rbegin() const 289280304Sjkim { return _M_t.rbegin(); } 290280304Sjkim 291280304Sjkim /** 292280304Sjkim * Returns a read/write reverse iterator that points to one before the 293280304Sjkim * first pair in the %multimap. Iteration is done in descending order 294280304Sjkim * according to the keys. 295280304Sjkim */ 296280304Sjkim reverse_iterator 297280304Sjkim rend() 298280304Sjkim { return _M_t.rend(); } 299280304Sjkim 300280304Sjkim /** 301280304Sjkim * Returns a read-only (constant) reverse iterator that points to one 302280304Sjkim * before the first pair in the %multimap. Iteration is done in 303280304Sjkim * descending order according to the keys. 304280304Sjkim */ 305280304Sjkim const_reverse_iterator 306280304Sjkim rend() const 307280304Sjkim { return _M_t.rend(); } 308280304Sjkim 309280304Sjkim // capacity 310280304Sjkim /** Returns true if the %multimap is empty. */ 311280304Sjkim bool 312280304Sjkim empty() const 313280304Sjkim { return _M_t.empty(); } 314280304Sjkim 315280304Sjkim /** Returns the size of the %multimap. */ 316280304Sjkim size_type 317280304Sjkim size() const 318280304Sjkim { return _M_t.size(); } 319280304Sjkim 32055714Skris /** Returns the maximum size of the %multimap. */ 321280304Sjkim size_type 322280304Sjkim max_size() const 323280304Sjkim { return _M_t.max_size(); } 32455714Skris 325280304Sjkim // modifiers 326280304Sjkim /** 32755714Skris * @brief Inserts a std::pair into the %multimap. 328280304Sjkim * @param x Pair to be inserted (see std::make_pair for easy creation 329280304Sjkim * of pairs). 330280304Sjkim * @return An iterator that points to the inserted (key,value) pair. 331280304Sjkim * 332280304Sjkim * This function inserts a (key, value) pair into the %multimap. 33355714Skris * Contrary to a std::map the %multimap does not rely on unique keys and 334280304Sjkim * thus multiple pairs with the same key can be inserted. 335280304Sjkim * 336280304Sjkim * Insertion requires logarithmic time. 337280304Sjkim */ 338280304Sjkim iterator 339280304Sjkim insert(const value_type& __x) 340280304Sjkim { return _M_t._M_insert_equal(__x); } 341280304Sjkim 342280304Sjkim /** 343306196Sjkim * @brief Inserts a std::pair into the %multimap. 344280304Sjkim * @param position An iterator that serves as a hint as to where the 345280304Sjkim * pair should be inserted. 346280304Sjkim * @param x Pair to be inserted (see std::make_pair for easy creation 347280304Sjkim * of pairs). 348280304Sjkim * @return An iterator that points to the inserted (key,value) pair. 349280304Sjkim * 350280304Sjkim * This function inserts a (key, value) pair into the %multimap. 35155714Skris * Contrary to a std::map the %multimap does not rely on unique keys and 352280304Sjkim * thus multiple pairs with the same key can be inserted. 353280304Sjkim * Note that the first parameter is only a hint and can potentially 354280304Sjkim * improve the performance of the insertion process. A bad hint would 355280304Sjkim * cause no gains in efficiency. 356280304Sjkim * 357280304Sjkim * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 358280304Sjkim * for more on "hinting". 359280304Sjkim * 360280304Sjkim * Insertion requires logarithmic time (if the hint is not taken). 36155714Skris */ 362280304Sjkim iterator 363280304Sjkim insert(iterator __position, const value_type& __x) 364280304Sjkim { return _M_t._M_insert_equal(__position, __x); } 365280304Sjkim 366280304Sjkim /** 367280304Sjkim * @brief A template function that attemps to insert a range of elements. 368280304Sjkim * @param first Iterator pointing to the start of the range to be 36955714Skris * inserted. 370280304Sjkim * @param last Iterator pointing to the end of the range. 371280304Sjkim * 372280304Sjkim * Complexity similar to that of the range constructor. 373280304Sjkim */ 374280304Sjkim template <typename _InputIterator> 375280304Sjkim void 37655714Skris insert(_InputIterator __first, _InputIterator __last) 377280304Sjkim { _M_t._M_insert_equal(__first, __last); } 378280304Sjkim 379280304Sjkim /** 380280304Sjkim * @brief Erases an element from a %multimap. 381280304Sjkim * @param position An iterator pointing to the element to be erased. 382280304Sjkim * 383280304Sjkim * This function erases an element, pointed to by the given iterator, 384280304Sjkim * from a %multimap. Note that this function only erases the element, 385280304Sjkim * and that if the element is itself a pointer, the pointed-to memory is 386280304Sjkim * not touched in any way. Managing the pointer is the user's 387280304Sjkim * responsibilty. 388280304Sjkim */ 389280304Sjkim void 390280304Sjkim erase(iterator __position) 391280304Sjkim { _M_t.erase(__position); } 392280304Sjkim 393280304Sjkim /** 394280304Sjkim * @brief Erases elements according to the provided key. 395280304Sjkim * @param x Key of element to be erased. 396280304Sjkim * @return The number of elements erased. 397280304Sjkim * 398280304Sjkim * This function erases all elements located by the given key from a 399280304Sjkim * %multimap. 400280304Sjkim * Note that this function only erases the element, and that if 401280304Sjkim * the element is itself a pointer, the pointed-to memory is not touched 402280304Sjkim * in any way. Managing the pointer is the user's responsibilty. 403280304Sjkim */ 40455714Skris size_type 405160814Ssimon erase(const key_type& __x) 406280304Sjkim { return _M_t.erase(__x); } 407280304Sjkim 408280304Sjkim /** 409280304Sjkim * @brief Erases a [first,last) range of elements from a %multimap. 410280304Sjkim * @param first Iterator pointing to the start of the range to be 411280304Sjkim * erased. 412280304Sjkim * @param last Iterator pointing to the end of the range to be erased. 413280304Sjkim * 414280304Sjkim * This function erases a sequence of elements from a %multimap. 415160814Ssimon * Note that this function only erases the elements, and that if 41655714Skris * the elements themselves are pointers, the pointed-to memory is not 41755714Skris * touched in any way. Managing the pointer is the user's responsibilty. 418280304Sjkim */ 419280304Sjkim void 420280304Sjkim erase(iterator __first, iterator __last) 421280304Sjkim { _M_t.erase(__first, __last); } 422280304Sjkim 423280304Sjkim /** 424280304Sjkim * @brief Swaps data with another %multimap. 425280304Sjkim * @param x A %multimap of the same element and allocator types. 426280304Sjkim * 427280304Sjkim * This exchanges the elements between two multimaps in constant time. 428280304Sjkim * (It is only swapping a pointer, an integer, and an instance of 429280304Sjkim * the @c Compare type (which itself is often stateless and empty), so it 430280304Sjkim * should be quite fast.) 431280304Sjkim * Note that the global std::swap() function is specialized such that 43255714Skris * std::swap(m1,m2) will feed to this function. 433280304Sjkim */ 434280304Sjkim void 435280304Sjkim swap(multimap& __x) 436280304Sjkim { _M_t.swap(__x._M_t); } 437280266Sdelphij 438280304Sjkim /** 439280304Sjkim * Erases all elements in a %multimap. Note that this function only 440280304Sjkim * erases the elements, and that if the elements themselves are pointers, 441280304Sjkim * the pointed-to memory is not touched in any way. Managing the pointer 442280266Sdelphij * is the user's responsibilty. 443280304Sjkim */ 444280304Sjkim void 44555714Skris clear() 446280304Sjkim { _M_t.clear(); } 447280304Sjkim 448284285Sjkim // observers 449284285Sjkim /** 450284285Sjkim * Returns the key comparison object out of which the %multimap 451284285Sjkim * was constructed. 452284285Sjkim */ 453284285Sjkim key_compare 454280304Sjkim key_comp() const 455280304Sjkim { return _M_t.key_comp(); } 456280304Sjkim 457280304Sjkim /** 458280304Sjkim * Returns a value comparison object, built from the key comparison 459280304Sjkim * object out of which the %multimap was constructed. 460280304Sjkim */ 461280304Sjkim value_compare 462280304Sjkim value_comp() const 463280304Sjkim { return value_compare(_M_t.key_comp()); } 464280304Sjkim 465284285Sjkim // multimap operations 466280304Sjkim /** 467280304Sjkim * @brief Tries to locate an element in a %multimap. 468280304Sjkim * @param x Key of (key, value) pair to be located. 469280304Sjkim * @return Iterator pointing to sought-after element, 470280304Sjkim * or end() if not found. 471280304Sjkim * 472280304Sjkim * This function takes a key and tries to locate the element with which 473280304Sjkim * the key matches. If successful the function returns an iterator 474280304Sjkim * pointing to the sought after %pair. If unsuccessful it returns the 475280304Sjkim * past-the-end ( @c end() ) iterator. 476280304Sjkim */ 477280304Sjkim iterator 478284285Sjkim find(const key_type& __x) 479280304Sjkim { return _M_t.find(__x); } 480280304Sjkim 481280304Sjkim /** 482280304Sjkim * @brief Tries to locate an element in a %multimap. 483280304Sjkim * @param x Key of (key, value) pair to be located. 484280304Sjkim * @return Read-only (constant) iterator pointing to sought-after 485280304Sjkim * element, or end() if not found. 486280304Sjkim * 487280304Sjkim * This function takes a key and tries to locate the element with which 488280304Sjkim * the key matches. If successful the function returns a constant 489280304Sjkim * iterator pointing to the sought after %pair. If unsuccessful it 490280304Sjkim * returns the past-the-end ( @c end() ) iterator. 49155714Skris */ 492284285Sjkim const_iterator 493284285Sjkim find(const key_type& __x) const 494284285Sjkim { return _M_t.find(__x); } 495284285Sjkim 496284285Sjkim /** 497284285Sjkim * @brief Finds the number of elements with given key. 498280304Sjkim * @param x Key of (key, value) pairs to be located. 499280304Sjkim * @return Number of elements with specified key. 500280304Sjkim */ 501280304Sjkim size_type 502280304Sjkim count(const key_type& __x) const 503280304Sjkim { return _M_t.count(__x); } 504280304Sjkim 505280304Sjkim /** 50655714Skris * @brief Finds the beginning of a subsequence matching given key. 507280304Sjkim * @param x Key of (key, value) pair to be located. 508280304Sjkim * @return Iterator pointing to first element equal to or greater 509280304Sjkim * than key, or end(). 510280304Sjkim * 511280304Sjkim * This function returns the first element of a subsequence of elements 512280304Sjkim * that matches the given key. If unsuccessful it returns an iterator 513280304Sjkim * pointing to the first element that has a greater value than given key 51455714Skris * or end() if no such element exists. 515280304Sjkim */ 516280304Sjkim iterator 517280304Sjkim lower_bound(const key_type& __x) 518280304Sjkim { return _M_t.lower_bound(__x); } 519280304Sjkim 520280304Sjkim /** 521280304Sjkim * @brief Finds the beginning of a subsequence matching given key. 522280304Sjkim * @param x Key of (key, value) pair to be located. 52355714Skris * @return Read-only (constant) iterator pointing to first element 524280304Sjkim * equal to or greater than key, or end(). 52555714Skris * 526280304Sjkim * This function returns the first element of a subsequence of elements 527280304Sjkim * that matches the given key. If unsuccessful the iterator will point 528280304Sjkim * to the next greatest element or, if no such greater element exists, to 529280304Sjkim * end(). 530280304Sjkim */ 531280304Sjkim const_iterator 53255714Skris lower_bound(const key_type& __x) const 53355714Skris { return _M_t.lower_bound(__x); } 534280304Sjkim 535280304Sjkim /** 536280304Sjkim * @brief Finds the end of a subsequence matching given key. 537280304Sjkim * @param x Key of (key, value) pair to be located. 53855714Skris * @return Iterator pointing to the first element 539280304Sjkim * greater than key, or end(). 540280304Sjkim */ 541280304Sjkim iterator 542280304Sjkim upper_bound(const key_type& __x) 54355714Skris { return _M_t.upper_bound(__x); } 544280304Sjkim 545280304Sjkim /** 546280304Sjkim * @brief Finds the end of a subsequence matching given key. 547280304Sjkim * @param x Key of (key, value) pair to be located. 54855714Skris * @return Read-only (constant) iterator pointing to first iterator 549280304Sjkim * greater than key, or end(). 550280304Sjkim */ 551280304Sjkim const_iterator 552280304Sjkim upper_bound(const key_type& __x) const 553280304Sjkim { return _M_t.upper_bound(__x); } 554280304Sjkim 555280304Sjkim /** 556280304Sjkim * @brief Finds a subsequence matching given key. 557280304Sjkim * @param x Key of (key, value) pairs to be located. 558280304Sjkim * @return Pair of iterators that possibly points to the subsequence 559280304Sjkim * matching given key. 560280304Sjkim * 561280304Sjkim * This function is equivalent to 56255714Skris * @code 563280304Sjkim * std::make_pair(c.lower_bound(val), 564280304Sjkim * c.upper_bound(val)) 565280304Sjkim * @endcode 566280304Sjkim * (but is faster than making the calls separately). 567280304Sjkim */ 568280304Sjkim std::pair<iterator, iterator> 569280304Sjkim equal_range(const key_type& __x) 570280304Sjkim { return _M_t.equal_range(__x); } 57155714Skris 572280304Sjkim /** 573280304Sjkim * @brief Finds a subsequence matching given key. 574280304Sjkim * @param x Key of (key, value) pairs to be located. 575280304Sjkim * @return Pair of read-only (constant) iterators that possibly points 576280304Sjkim * to the subsequence matching given key. 577280304Sjkim * 578280304Sjkim * This function is equivalent to 579280304Sjkim * @code 580280304Sjkim * std::make_pair(c.lower_bound(val), 581280304Sjkim * c.upper_bound(val)) 58255714Skris * @endcode 583280304Sjkim * (but is faster than making the calls separately). 584280304Sjkim */ 585280304Sjkim std::pair<const_iterator, const_iterator> 586280304Sjkim equal_range(const key_type& __x) const 587280304Sjkim { return _M_t.equal_range(__x); } 588280304Sjkim 589280304Sjkim template <typename _K1, typename _T1, typename _C1, typename _A1> 590280304Sjkim friend bool 591280304Sjkim operator== (const multimap<_K1, _T1, _C1, _A1>&, 592280304Sjkim const multimap<_K1, _T1, _C1, _A1>&); 593280304Sjkim 594280304Sjkim template <typename _K1, typename _T1, typename _C1, typename _A1> 595280304Sjkim friend bool 596280304Sjkim operator< (const multimap<_K1, _T1, _C1, _A1>&, 597280304Sjkim const multimap<_K1, _T1, _C1, _A1>&); 598280304Sjkim }; 599280304Sjkim 600280304Sjkim /** 60155714Skris * @brief Multimap equality comparison. 602280304Sjkim * @param x A %multimap. 603280304Sjkim * @param y A %multimap of the same type as @a x. 604280304Sjkim * @return True iff the size and elements of the maps are equal. 605280304Sjkim * 606280304Sjkim * This is an equivalence relation. It is linear in the size of the 607280304Sjkim * multimaps. Multimaps are considered equivalent if their sizes are equal, 608280304Sjkim * and if corresponding elements compare equal. 609280304Sjkim */ 610280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 611280304Sjkim inline bool 612280304Sjkim operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 613280304Sjkim const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 614280304Sjkim { return __x._M_t == __y._M_t; } 615280304Sjkim 616280304Sjkim /** 617280304Sjkim * @brief Multimap ordering relation. 618280304Sjkim * @param x A %multimap. 619280304Sjkim * @param y A %multimap of the same type as @a x. 620280304Sjkim * @return True iff @a x is lexicographically less than @a y. 621234954Sbz * 622280304Sjkim * This is a total ordering relation. It is linear in the size of the 623280304Sjkim * multimaps. The elements must be comparable with @c <. 624280304Sjkim * 625280304Sjkim * See std::lexicographical_compare() for how the determination is made. 626280304Sjkim */ 627280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 628280304Sjkim inline bool 629280304Sjkim operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 630280304Sjkim const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 631280304Sjkim { return __x._M_t < __y._M_t; } 63255714Skris 633280304Sjkim /// Based on operator== 634280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 635280304Sjkim inline bool 636280304Sjkim operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 637280304Sjkim const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 638280304Sjkim { return !(__x == __y); } 63955714Skris 640284285Sjkim /// Based on operator< 641280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 642280304Sjkim inline bool 643280304Sjkim operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 644280304Sjkim const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 645280304Sjkim { return __y < __x; } 646280304Sjkim 647280304Sjkim /// Based on operator< 648280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 649280304Sjkim inline bool 650280304Sjkim operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 65155714Skris const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 652280304Sjkim { return !(__y < __x); } 653280304Sjkim 654280304Sjkim /// Based on operator< 655280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 656280304Sjkim inline bool 657280304Sjkim operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 658280304Sjkim const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 659291721Sjkim { return !(__x < __y); } 660291721Sjkim 661280304Sjkim /// See std::multimap::swap(). 662280304Sjkim template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 663280304Sjkim inline void 664280304Sjkim swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, 665280304Sjkim multimap<_Key, _Tp, _Compare, _Alloc>& __y) 666280304Sjkim { __x.swap(__y); } 667280304Sjkim 668280304Sjkim_GLIBCXX_END_NESTED_NAMESPACE 66959191Skris 670280304Sjkim#endif /* _MULTIMAP_H */ 671280304Sjkim