stl_map.h revision 132720
197403Sobrien// Map implementation -*- C++ -*- 297403Sobrien 3132720Skan// Copyright (C) 2001, 2002, 2004 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 1897403Sobrien// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_map.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 _MAP_H 62132720Skan#define _MAP_H 1 6397403Sobrien 6497403Sobrien#include <bits/concept_check.h> 6597403Sobrien 66132720Skannamespace _GLIBCXX_STD 6797403Sobrien{ 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 unique keys). 78117397Skan * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the 79117397Skan * value_type is std::pair<const Key,T>. 8097403Sobrien * 81117397Skan * Maps 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 */ 89117397Skan template <typename _Key, typename _Tp, typename _Compare = less<_Key>, 90117397Skan typename _Alloc = allocator<pair<const _Key, _Tp> > > 91117397Skan class map 92132720Skan { 93132720Skan // concept requirements 94132720Skan __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 95132720Skan __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 96132720Skan _BinaryFunctionConcept) 97132720Skan 98132720Skan public: 99132720Skan typedef _Key key_type; 100132720Skan typedef _Tp mapped_type; 101132720Skan typedef pair<const _Key, _Tp> value_type; 102132720Skan typedef _Compare key_compare; 103132720Skan 104132720Skan class value_compare 105117397Skan : public binary_function<value_type, value_type, bool> 106117397Skan { 107132720Skan friend class map<_Key,_Tp,_Compare,_Alloc>; 108117397Skan protected: 109132720Skan _Compare comp; 110132720Skan 111132720Skan value_compare(_Compare __c) 112132720Skan : comp(__c) { } 113132720Skan 114117397Skan public: 115132720Skan bool operator()(const value_type& __x, const value_type& __y) const 116132720Skan { return comp(__x.first, __y.first); } 117117397Skan }; 118132720Skan 119132720Skan private: 120132720Skan /// @if maint This turns a red-black tree into a [multi]map. @endif 121132720Skan typedef _Rb_tree<key_type, value_type, 122132720Skan _Select1st<value_type>, key_compare, _Alloc> _Rep_type; 123132720Skan /// @if maint The actual tree structure. @endif 124132720Skan _Rep_type _M_t; 125132720Skan 126132720Skan public: 127132720Skan // many of these are specified differently in ISO, but the following are 128132720Skan // "functionally equivalent" 129132720Skan typedef typename _Alloc::pointer pointer; 130132720Skan typedef typename _Alloc::const_pointer const_pointer; 131132720Skan typedef typename _Alloc::reference reference; 132132720Skan typedef typename _Alloc::const_reference const_reference; 133132720Skan typedef typename _Rep_type::allocator_type allocator_type; 134132720Skan typedef typename _Rep_type::iterator iterator; 135132720Skan typedef typename _Rep_type::const_iterator const_iterator; 136132720Skan typedef typename _Rep_type::size_type size_type; 137132720Skan typedef typename _Rep_type::difference_type difference_type; 138132720Skan typedef typename _Rep_type::reverse_iterator reverse_iterator; 139132720Skan typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 140132720Skan 141132720Skan // [23.3.1.1] construct/copy/destroy 142132720Skan // (get_allocator() is normally listed in this section, but seems to have 143132720Skan // been accidentally omitted in the printed standard) 144132720Skan /** 145132720Skan * @brief Default constructor creates no elements. 146132720Skan */ 147132720Skan map() 148132720Skan : _M_t(_Compare(), allocator_type()) { } 149132720Skan 150132720Skan // for some reason this was made a separate function 151132720Skan /** 152132720Skan * @brief Default constructor creates no elements. 153132720Skan */ 154132720Skan explicit 155132720Skan map(const _Compare& __comp, const allocator_type& __a = allocator_type()) 156117397Skan : _M_t(__comp, __a) { } 157132720Skan 158132720Skan /** 159132720Skan * @brief Map copy constructor. 160132720Skan * @param x A %map of identical element and allocator types. 161132720Skan * 162132720Skan * The newly-created %map uses a copy of the allocation object used 163132720Skan * by @a x. 164132720Skan */ 165132720Skan map(const map& __x) 166117397Skan : _M_t(__x._M_t) { } 167132720Skan 168132720Skan /** 169132720Skan * @brief Builds a %map from a range. 170132720Skan * @param first An input iterator. 171132720Skan * @param last An input iterator. 172132720Skan * 173132720Skan * Create a %map consisting of copies of the elements from [first,last). 174132720Skan * This is linear in N if the range is already sorted, and NlogN 175132720Skan * otherwise (where N is distance(first,last)). 176132720Skan */ 177132720Skan template <typename _InputIterator> 178132720Skan map(_InputIterator __first, _InputIterator __last) 179132720Skan : _M_t(_Compare(), allocator_type()) 180132720Skan { _M_t.insert_unique(__first, __last); } 181132720Skan 182132720Skan /** 183132720Skan * @brief Builds a %map from a range. 184132720Skan * @param first An input iterator. 185132720Skan * @param last An input iterator. 186132720Skan * @param comp A comparison functor. 187132720Skan * @param a An allocator object. 188132720Skan * 189132720Skan * Create a %map consisting of copies of the elements from [first,last). 190132720Skan * This is linear in N if the range is already sorted, and NlogN 191132720Skan * otherwise (where N is distance(first,last)). 192132720Skan */ 193132720Skan template <typename _InputIterator> 194132720Skan map(_InputIterator __first, _InputIterator __last, 195132720Skan const _Compare& __comp, const allocator_type& __a = allocator_type()) 196132720Skan : _M_t(__comp, __a) 197132720Skan { _M_t.insert_unique(__first, __last); } 198132720Skan 199132720Skan // FIXME There is no dtor declared, but we should have something generated 200132720Skan // by Doxygen. I don't know what tags to add to this paragraph to make 201132720Skan // that happen: 202132720Skan /** 203132720Skan * The dtor only erases the elements, and note that if the elements 204132720Skan * themselves are pointers, the pointed-to memory is not touched in any 205132720Skan * way. Managing the pointer is the user's responsibilty. 206132720Skan */ 207132720Skan 208132720Skan /** 209132720Skan * @brief Map assignment operator. 210132720Skan * @param x A %map of identical element and allocator types. 211132720Skan * 212132720Skan * All the elements of @a x are copied, but unlike the copy constructor, 213132720Skan * the allocator object is not copied. 214132720Skan */ 215132720Skan map& 216132720Skan operator=(const map& __x) 217132720Skan { 218132720Skan _M_t = __x._M_t; 219132720Skan return *this; 220132720Skan } 221132720Skan 222132720Skan /// Get a copy of the memory allocation object. 223132720Skan allocator_type 224132720Skan get_allocator() const 225132720Skan { return _M_t.get_allocator(); } 226132720Skan 227132720Skan // iterators 228132720Skan /** 229132720Skan * Returns a read/write iterator that points to the first pair in the 230132720Skan * %map. 231132720Skan * Iteration is done in ascending order according to the keys. 232132720Skan */ 233132720Skan iterator 234132720Skan begin() 235132720Skan { return _M_t.begin(); } 236132720Skan 237132720Skan /** 238132720Skan * Returns a read-only (constant) iterator that points to the first pair 239132720Skan * in the %map. Iteration is done in ascending order according to the 240132720Skan * keys. 241132720Skan */ 242132720Skan const_iterator 243132720Skan begin() const 244132720Skan { return _M_t.begin(); } 245132720Skan 246132720Skan /** 247132720Skan * Returns a read/write iterator that points one past the last pair in 248132720Skan * the %map. Iteration is done in ascending order according to the keys. 249132720Skan */ 250132720Skan iterator 251132720Skan end() 252132720Skan { return _M_t.end(); } 253132720Skan 254132720Skan /** 255132720Skan * Returns a read-only (constant) iterator that points one past the last 256132720Skan * pair in the %map. Iteration is done in ascending order according to 257132720Skan * the keys. 258132720Skan */ 259132720Skan const_iterator 260132720Skan end() const 261132720Skan { return _M_t.end(); } 262132720Skan 263132720Skan /** 264132720Skan * Returns a read/write reverse iterator that points to the last pair in 265132720Skan * the %map. Iteration is done in descending order according to the 266132720Skan * keys. 267132720Skan */ 268132720Skan reverse_iterator 269132720Skan rbegin() 270132720Skan { return _M_t.rbegin(); } 271132720Skan 272132720Skan /** 273132720Skan * Returns a read-only (constant) reverse iterator that points to the 274132720Skan * last pair in the %map. Iteration is done in descending order 275132720Skan * according to the keys. 276132720Skan */ 277132720Skan const_reverse_iterator 278132720Skan rbegin() const 279132720Skan { return _M_t.rbegin(); } 280132720Skan 281132720Skan /** 282132720Skan * Returns a read/write reverse iterator that points to one before the 283132720Skan * first pair in the %map. Iteration is done in descending order 284132720Skan * according to the keys. 285132720Skan */ 286132720Skan reverse_iterator 287132720Skan rend() 288132720Skan { return _M_t.rend(); } 289132720Skan 290132720Skan /** 291132720Skan * Returns a read-only (constant) reverse iterator that points to one 292132720Skan * before the first pair in the %map. Iteration is done in descending 293132720Skan * order according to the keys. 294132720Skan */ 295132720Skan const_reverse_iterator 296132720Skan rend() const 297132720Skan { return _M_t.rend(); } 298132720Skan 299132720Skan // capacity 300132720Skan /** Returns true if the %map is empty. (Thus begin() would equal 301132720Skan * end().) 302132720Skan */ 303132720Skan bool 304132720Skan empty() const 305132720Skan { return _M_t.empty(); } 306132720Skan 307132720Skan /** Returns the size of the %map. */ 308132720Skan size_type 309132720Skan size() const 310132720Skan { return _M_t.size(); } 311132720Skan 312132720Skan /** Returns the maximum size of the %map. */ 313132720Skan size_type 314132720Skan max_size() const 315132720Skan { return _M_t.max_size(); } 316132720Skan 317132720Skan // [23.3.1.2] element access 318132720Skan /** 319132720Skan * @brief Subscript ( @c [] ) access to %map data. 320132720Skan * @param k The key for which data should be retrieved. 321132720Skan * @return A reference to the data of the (key,data) %pair. 322132720Skan * 323132720Skan * Allows for easy lookup with the subscript ( @c [] ) operator. Returns 324132720Skan * data associated with the key specified in subscript. If the key does 325132720Skan * not exist, a pair with that key is created using default values, which 326132720Skan * is then returned. 327132720Skan * 328132720Skan * Lookup requires logarithmic time. 329132720Skan */ 330132720Skan mapped_type& 331132720Skan operator[](const key_type& __k) 332132720Skan { 333132720Skan // concept requirements 334132720Skan __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) 335132720Skan 336132720Skan iterator __i = lower_bound(__k); 337132720Skan // __i->first is greater than or equivalent to __k. 338132720Skan if (__i == end() || key_comp()(__k, (*__i).first)) 339132720Skan __i = insert(__i, value_type(__k, mapped_type())); 340132720Skan return (*__i).second; 341132720Skan } 342132720Skan 343132720Skan // modifiers 344132720Skan /** 345132720Skan * @brief Attempts to insert a std::pair into the %map. 346132720Skan * @param x Pair to be inserted (see std::make_pair for easy creation of 347132720Skan * pairs). 348132720Skan * @return A pair, of which the first element is an iterator that points 349132720Skan * to the possibly inserted pair, and the second is a bool that 350132720Skan * is true if the pair was actually inserted. 351132720Skan * 352132720Skan * This function attempts to insert a (key, value) %pair into the %map. 353132720Skan * A %map relies on unique keys and thus a %pair is only inserted if its 354132720Skan * first element (the key) is not already present in the %map. 355132720Skan * 356132720Skan * Insertion requires logarithmic time. 357132720Skan */ 358132720Skan pair<iterator,bool> 359132720Skan insert(const value_type& __x) 360132720Skan { return _M_t.insert_unique(__x); } 361132720Skan 362132720Skan /** 363132720Skan * @brief Attempts to insert a std::pair into the %map. 364132720Skan * @param position An iterator that serves as a hint as to where the 365132720Skan * pair should be inserted. 366132720Skan * @param x Pair to be inserted (see std::make_pair for easy creation of 367132720Skan * pairs). 368132720Skan * @return An iterator that points to the element with key of @a x (may 369132720Skan * or may not be the %pair passed in). 370132720Skan * 371132720Skan * This function is not concerned about whether the insertion took place, 372132720Skan * and thus does not return a boolean like the single-argument 373132720Skan * insert() does. Note that the first parameter is only a hint and can 374132720Skan * potentially improve the performance of the insertion process. A bad 375132720Skan * hint would cause no gains in efficiency. 376132720Skan * 377132720Skan * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 378132720Skan * for more on "hinting". 379132720Skan * 380132720Skan * Insertion requires logarithmic time (if the hint is not taken). 381132720Skan */ 382132720Skan iterator 383132720Skan insert(iterator position, const value_type& __x) 384132720Skan { return _M_t.insert_unique(position, __x); } 385132720Skan 386132720Skan /** 387132720Skan * @brief A template function that attemps to insert a range of elements. 388132720Skan * @param first Iterator pointing to the start of the range to be 389132720Skan * inserted. 390132720Skan * @param last Iterator pointing to the end of the range. 391132720Skan * 392132720Skan * Complexity similar to that of the range constructor. 393132720Skan */ 394132720Skan template <typename _InputIterator> 395132720Skan void 396132720Skan insert(_InputIterator __first, _InputIterator __last) 397132720Skan { _M_t.insert_unique(__first, __last); } 398132720Skan 399132720Skan /** 400132720Skan * @brief Erases an element from a %map. 401132720Skan * @param position An iterator pointing to the element to be erased. 402132720Skan * 403132720Skan * This function erases an element, pointed to by the given iterator, 404132720Skan * from a %map. Note that this function only erases the element, and 405132720Skan * that if the element is itself a pointer, the pointed-to memory is not 406132720Skan * touched in any way. Managing the pointer is the user's responsibilty. 407132720Skan */ 408117397Skan void 409132720Skan erase(iterator __position) 410132720Skan { _M_t.erase(__position); } 411132720Skan 412132720Skan /** 413132720Skan * @brief Erases elements according to the provided key. 414132720Skan * @param x Key of element to be erased. 415132720Skan * @return The number of elements erased. 416132720Skan * 417132720Skan * This function erases all the elements located by the given key from 418132720Skan * a %map. 419132720Skan * Note that this function only erases the element, and that if 420132720Skan * the element is itself a pointer, the pointed-to memory is not touched 421132720Skan * in any way. Managing the pointer is the user's responsibilty. 422132720Skan */ 423132720Skan size_type 424132720Skan erase(const key_type& __x) 425132720Skan { return _M_t.erase(__x); } 426132720Skan 427132720Skan /** 428132720Skan * @brief Erases a [first,last) range of elements from a %map. 429132720Skan * @param first Iterator pointing to the start of the range to be 430132720Skan * erased. 431132720Skan * @param last Iterator pointing to the end of the range to be erased. 432132720Skan * 433132720Skan * This function erases a sequence of elements from a %map. 434132720Skan * Note that this function only erases the element, and that if 435132720Skan * the element is itself a pointer, the pointed-to memory is not touched 436132720Skan * in any way. Managing the pointer is the user's responsibilty. 437132720Skan */ 438132720Skan void 439132720Skan erase(iterator __first, iterator __last) 440132720Skan { _M_t.erase(__first, __last); } 441132720Skan 442132720Skan /** 443132720Skan * @brief Swaps data with another %map. 444132720Skan * @param x A %map of the same element and allocator types. 445132720Skan * 446132720Skan * This exchanges the elements between two maps in constant time. 447132720Skan * (It is only swapping a pointer, an integer, and an instance of 448132720Skan * the @c Compare type (which itself is often stateless and empty), so it 449132720Skan * should be quite fast.) 450132720Skan * Note that the global std::swap() function is specialized such that 451132720Skan * std::swap(m1,m2) will feed to this function. 452132720Skan */ 453132720Skan void 454132720Skan swap(map& __x) 455132720Skan { _M_t.swap(__x._M_t); } 456132720Skan 457132720Skan /** 458132720Skan * Erases all elements in a %map. Note that this function only erases 459132720Skan * the elements, and that if the elements themselves are pointers, the 460132720Skan * pointed-to memory is not touched in any way. Managing the pointer is 461132720Skan * the user's responsibilty. 462132720Skan */ 463132720Skan void 464132720Skan clear() 465132720Skan { _M_t.clear(); } 466132720Skan 467132720Skan // observers 468132720Skan /** 469132720Skan * Returns the key comparison object out of which the %map was 470132720Skan * constructed. 471132720Skan */ 472132720Skan key_compare 473132720Skan key_comp() const 474132720Skan { return _M_t.key_comp(); } 475132720Skan 476132720Skan /** 477132720Skan * Returns a value comparison object, built from the key comparison 478132720Skan * object out of which the %map was constructed. 479132720Skan */ 480132720Skan value_compare 481132720Skan value_comp() const 482132720Skan { return value_compare(_M_t.key_comp()); } 483132720Skan 484132720Skan // [23.3.1.3] map operations 485132720Skan /** 486132720Skan * @brief Tries to locate an element in a %map. 487132720Skan * @param x Key of (key, value) %pair to be located. 488132720Skan * @return Iterator pointing to sought-after element, or end() if not 489132720Skan * found. 490132720Skan * 491132720Skan * This function takes a key and tries to locate the element with which 492132720Skan * the key matches. If successful the function returns an iterator 493132720Skan * pointing to the sought after %pair. If unsuccessful it returns the 494132720Skan * past-the-end ( @c end() ) iterator. 495132720Skan */ 496132720Skan iterator 497132720Skan find(const key_type& __x) 498132720Skan { return _M_t.find(__x); } 499132720Skan 500132720Skan /** 501132720Skan * @brief Tries to locate an element in a %map. 502132720Skan * @param x Key of (key, value) %pair to be located. 503132720Skan * @return Read-only (constant) iterator pointing to sought-after 504132720Skan * element, or end() if not found. 505132720Skan * 506132720Skan * This function takes a key and tries to locate the element with which 507132720Skan * the key matches. If successful the function returns a constant 508132720Skan * iterator pointing to the sought after %pair. If unsuccessful it 509132720Skan * returns the past-the-end ( @c end() ) iterator. 510132720Skan */ 511132720Skan const_iterator 512132720Skan find(const key_type& __x) const 513132720Skan { return _M_t.find(__x); } 514132720Skan 515132720Skan /** 516132720Skan * @brief Finds the number of elements with given key. 517132720Skan * @param x Key of (key, value) pairs to be located. 518132720Skan * @return Number of elements with specified key. 519132720Skan * 520132720Skan * This function only makes sense for multimaps; for map the result will 521132720Skan * either be 0 (not present) or 1 (present). 522132720Skan */ 523132720Skan size_type 524132720Skan count(const key_type& __x) const 525132720Skan { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } 526132720Skan 527132720Skan /** 528132720Skan * @brief Finds the beginning of a subsequence matching given key. 529132720Skan * @param x Key of (key, value) pair to be located. 530132720Skan * @return Iterator pointing to first element equal to or greater 531132720Skan * than key, or end(). 532132720Skan * 533132720Skan * This function returns the first element of a subsequence of elements 534132720Skan * that matches the given key. If unsuccessful it returns an iterator 535132720Skan * pointing to the first element that has a greater value than given key 536132720Skan * or end() if no such element exists. 537132720Skan */ 538132720Skan iterator 539132720Skan lower_bound(const key_type& __x) 540132720Skan { return _M_t.lower_bound(__x); } 541132720Skan 542132720Skan /** 543132720Skan * @brief Finds the beginning of a subsequence matching given key. 544132720Skan * @param x Key of (key, value) pair to be located. 545132720Skan * @return Read-only (constant) iterator pointing to first element 546132720Skan * equal to or greater than key, or end(). 547132720Skan * 548132720Skan * This function returns the first element of a subsequence of elements 549132720Skan * that matches the given key. If unsuccessful it returns an iterator 550132720Skan * pointing to the first element that has a greater value than given key 551132720Skan * or end() if no such element exists. 552132720Skan */ 553132720Skan const_iterator 554132720Skan lower_bound(const key_type& __x) const 555132720Skan { return _M_t.lower_bound(__x); } 556132720Skan 557132720Skan /** 558132720Skan * @brief Finds the end of a subsequence matching given key. 559132720Skan * @param x Key of (key, value) pair to be located. 560132720Skan * @return Iterator pointing to the first element 561132720Skan * greater than key, or end(). 562132720Skan */ 563132720Skan iterator 564132720Skan upper_bound(const key_type& __x) 565132720Skan { return _M_t.upper_bound(__x); } 566132720Skan 567132720Skan /** 568132720Skan * @brief Finds the end of a subsequence matching given key. 569132720Skan * @param x Key of (key, value) pair to be located. 570132720Skan * @return Read-only (constant) iterator pointing to first iterator 571132720Skan * greater than key, or end(). 572132720Skan */ 573132720Skan const_iterator 574132720Skan upper_bound(const key_type& __x) const 575132720Skan { return _M_t.upper_bound(__x); } 576132720Skan 577132720Skan /** 578132720Skan * @brief Finds a subsequence matching given key. 579132720Skan * @param x Key of (key, value) pairs to be located. 580132720Skan * @return Pair of iterators that possibly points to the subsequence 581132720Skan * matching given key. 582132720Skan * 583132720Skan * This function is equivalent to 584132720Skan * @code 585132720Skan * std::make_pair(c.lower_bound(val), 586132720Skan * c.upper_bound(val)) 587132720Skan * @endcode 588132720Skan * (but is faster than making the calls separately). 589132720Skan * 590132720Skan * This function probably only makes sense for multimaps. 591132720Skan */ 592132720Skan pair<iterator,iterator> 593132720Skan equal_range(const key_type& __x) 594132720Skan { return _M_t.equal_range(__x); } 595132720Skan 596132720Skan /** 597132720Skan * @brief Finds a subsequence matching given key. 598132720Skan * @param x Key of (key, value) pairs to be located. 599132720Skan * @return Pair of read-only (constant) iterators that possibly points 600132720Skan * to the subsequence matching given key. 601132720Skan * 602132720Skan * This function is equivalent to 603132720Skan * @code 604132720Skan * std::make_pair(c.lower_bound(val), 605132720Skan * c.upper_bound(val)) 606132720Skan * @endcode 607132720Skan * (but is faster than making the calls separately). 608132720Skan * 609132720Skan * This function probably only makes sense for multimaps. 610132720Skan */ 611132720Skan pair<const_iterator,const_iterator> 612132720Skan equal_range(const key_type& __x) const 613132720Skan { return _M_t.equal_range(__x); } 614132720Skan 615132720Skan template <typename _K1, typename _T1, typename _C1, typename _A1> 616132720Skan friend bool 617132720Skan operator== (const map<_K1,_T1,_C1,_A1>&, 618132720Skan const map<_K1,_T1,_C1,_A1>&); 619132720Skan 620132720Skan template <typename _K1, typename _T1, typename _C1, typename _A1> 621132720Skan friend bool 622132720Skan operator< (const map<_K1,_T1,_C1,_A1>&, 623132720Skan const map<_K1,_T1,_C1,_A1>&); 624132720Skan }; 625132720Skan 62697403Sobrien /** 627117397Skan * @brief Map equality comparison. 628117397Skan * @param x A %map. 629117397Skan * @param y A %map of the same type as @a x. 630117397Skan * @return True iff the size and elements of the maps are equal. 63197403Sobrien * 632117397Skan * This is an equivalence relation. It is linear in the size of the 633117397Skan * maps. Maps are considered equivalent if their sizes are equal, 634117397Skan * and if corresponding elements compare equal. 63597403Sobrien */ 636117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 637117397Skan inline bool 638117397Skan operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x, 639117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 640117397Skan { return __x._M_t == __y._M_t; } 641132720Skan 64297403Sobrien /** 643117397Skan * @brief Map ordering relation. 644117397Skan * @param x A %map. 645117397Skan * @param y A %map of the same type as @a x. 646132720Skan * @return True iff @a x is lexicographically less than @a y. 64797403Sobrien * 648117397Skan * This is a total ordering relation. It is linear in the size of the 649117397Skan * maps. The elements must be comparable with @c <. 65097403Sobrien * 651132720Skan * See std::lexicographical_compare() for how the determination is made. 65297403Sobrien */ 653117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 654117397Skan inline bool 655117397Skan operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x, 656117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 657117397Skan { return __x._M_t < __y._M_t; } 658132720Skan 659117397Skan /// Based on operator== 660117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 661117397Skan inline bool 662117397Skan operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x, 663117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 664117397Skan { return !(__x == __y); } 665132720Skan 666117397Skan /// Based on operator< 667117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 668117397Skan inline bool 669117397Skan operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x, 670117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 671117397Skan { return __y < __x; } 672132720Skan 673117397Skan /// Based on operator< 674117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 675117397Skan inline bool 676117397Skan operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x, 677117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 678117397Skan { return !(__y < __x); } 679132720Skan 680117397Skan /// Based on operator< 681117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 682117397Skan inline bool 683117397Skan operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x, 684117397Skan const map<_Key,_Tp,_Compare,_Alloc>& __y) 685117397Skan { return !(__x < __y); } 686132720Skan 687117397Skan /// See std::map::swap(). 688117397Skan template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 689117397Skan inline void 690117397Skan swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y) 691117397Skan { __x.swap(__y); } 69297403Sobrien} // namespace std 69397403Sobrien 694132720Skan#endif /* _MAP_H */ 695