1951a39d68df598db08dfced8b4707755864a0492Ying Wang// Debugging map implementation -*- C++ -*- 2951a39d68df598db08dfced8b4707755864a0492Ying Wang 3951a39d68df598db08dfced8b4707755864a0492Ying Wang// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 4951a39d68df598db08dfced8b4707755864a0492Ying Wang// Free Software Foundation, Inc. 5951a39d68df598db08dfced8b4707755864a0492Ying Wang// 6951a39d68df598db08dfced8b4707755864a0492Ying Wang// This file is part of the GNU ISO C++ Library. This library is free 7951a39d68df598db08dfced8b4707755864a0492Ying Wang// software; you can redistribute it and/or modify it under the 8951a39d68df598db08dfced8b4707755864a0492Ying Wang// terms of the GNU General Public License as published by the 9951a39d68df598db08dfced8b4707755864a0492Ying Wang// Free Software Foundation; either version 3, or (at your option) 10951a39d68df598db08dfced8b4707755864a0492Ying Wang// any later version. 11951a39d68df598db08dfced8b4707755864a0492Ying Wang 12951a39d68df598db08dfced8b4707755864a0492Ying Wang// This library is distributed in the hope that it will be useful, 13951a39d68df598db08dfced8b4707755864a0492Ying Wang// but WITHOUT ANY WARRANTY; without even the implied warranty of 14951a39d68df598db08dfced8b4707755864a0492Ying Wang// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15951a39d68df598db08dfced8b4707755864a0492Ying Wang// GNU General Public License for more details. 16951a39d68df598db08dfced8b4707755864a0492Ying Wang 17951a39d68df598db08dfced8b4707755864a0492Ying Wang// Under Section 7 of GPL version 3, you are granted additional 18951a39d68df598db08dfced8b4707755864a0492Ying Wang// permissions described in the GCC Runtime Library Exception, version 19951a39d68df598db08dfced8b4707755864a0492Ying Wang// 3.1, as published by the Free Software Foundation. 20951a39d68df598db08dfced8b4707755864a0492Ying Wang 21951a39d68df598db08dfced8b4707755864a0492Ying Wang// You should have received a copy of the GNU General Public License and 22951a39d68df598db08dfced8b4707755864a0492Ying Wang// a copy of the GCC Runtime Library Exception along with this program; 23951a39d68df598db08dfced8b4707755864a0492Ying Wang// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24951a39d68df598db08dfced8b4707755864a0492Ying Wang// <http://www.gnu.org/licenses/>. 25951a39d68df598db08dfced8b4707755864a0492Ying Wang 26951a39d68df598db08dfced8b4707755864a0492Ying Wang/** @file debug/map.h 27951a39d68df598db08dfced8b4707755864a0492Ying Wang * This file is a GNU debug extension to the Standard C++ Library. 28951a39d68df598db08dfced8b4707755864a0492Ying Wang */ 29951a39d68df598db08dfced8b4707755864a0492Ying Wang 30951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifndef _GLIBCXX_DEBUG_MAP_H 31951a39d68df598db08dfced8b4707755864a0492Ying Wang#define _GLIBCXX_DEBUG_MAP_H 1 32951a39d68df598db08dfced8b4707755864a0492Ying Wang 33951a39d68df598db08dfced8b4707755864a0492Ying Wang#include <debug/safe_sequence.h> 34951a39d68df598db08dfced8b4707755864a0492Ying Wang#include <debug/safe_iterator.h> 35951a39d68df598db08dfced8b4707755864a0492Ying Wang#include <utility> 36951a39d68df598db08dfced8b4707755864a0492Ying Wang 37951a39d68df598db08dfced8b4707755864a0492Ying Wangnamespace std 38951a39d68df598db08dfced8b4707755864a0492Ying Wang{ 39951a39d68df598db08dfced8b4707755864a0492Ying Wangnamespace __debug 40951a39d68df598db08dfced8b4707755864a0492Ying Wang{ 41951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>, 42951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > > 43951a39d68df598db08dfced8b4707755864a0492Ying Wang class map 44951a39d68df598db08dfced8b4707755864a0492Ying Wang : public _GLIBCXX_STD_D::map<_Key, _Tp, _Compare, _Allocator>, 45951a39d68df598db08dfced8b4707755864a0492Ying Wang public __gnu_debug::_Safe_sequence<map<_Key, _Tp, _Compare, _Allocator> > 46951a39d68df598db08dfced8b4707755864a0492Ying Wang { 47951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef _GLIBCXX_STD_D::map<_Key, _Tp, _Compare, _Allocator> _Base; 48951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef __gnu_debug::_Safe_sequence<map> _Safe_base; 49951a39d68df598db08dfced8b4707755864a0492Ying Wang 50951a39d68df598db08dfced8b4707755864a0492Ying Wang public: 51951a39d68df598db08dfced8b4707755864a0492Ying Wang // types: 52951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef _Key key_type; 53951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef _Tp mapped_type; 54951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef std::pair<const _Key, _Tp> value_type; 55951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef _Compare key_compare; 56951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef _Allocator allocator_type; 57951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::reference reference; 58951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::const_reference const_reference; 59951a39d68df598db08dfced8b4707755864a0492Ying Wang 60951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, map> 61951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator; 62951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, map> 63951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator; 64951a39d68df598db08dfced8b4707755864a0492Ying Wang 65951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::size_type size_type; 66951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::difference_type difference_type; 67951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::pointer pointer; 68951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::const_pointer const_pointer; 69951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef std::reverse_iterator<iterator> reverse_iterator; 70951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 71951a39d68df598db08dfced8b4707755864a0492Ying Wang 72951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::value_compare; 73951a39d68df598db08dfced8b4707755864a0492Ying Wang 74951a39d68df598db08dfced8b4707755864a0492Ying Wang // 23.3.1.1 construct/copy/destroy: 75951a39d68df598db08dfced8b4707755864a0492Ying Wang explicit map(const _Compare& __comp = _Compare(), 76951a39d68df598db08dfced8b4707755864a0492Ying Wang const _Allocator& __a = _Allocator()) 77951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(__comp, __a) { } 78951a39d68df598db08dfced8b4707755864a0492Ying Wang 79951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _InputIterator> 80951a39d68df598db08dfced8b4707755864a0492Ying Wang map(_InputIterator __first, _InputIterator __last, 81951a39d68df598db08dfced8b4707755864a0492Ying Wang const _Compare& __comp = _Compare(), 82951a39d68df598db08dfced8b4707755864a0492Ying Wang const _Allocator& __a = _Allocator()) 83951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(__gnu_debug::__check_valid_range(__first, __last), __last, 84951a39d68df598db08dfced8b4707755864a0492Ying Wang __comp, __a), _Safe_base() { } 85951a39d68df598db08dfced8b4707755864a0492Ying Wang 86951a39d68df598db08dfced8b4707755864a0492Ying Wang map(const map& __x) 87951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(__x), _Safe_base() { } 88951a39d68df598db08dfced8b4707755864a0492Ying Wang 89951a39d68df598db08dfced8b4707755864a0492Ying Wang map(const _Base& __x) 90951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(__x), _Safe_base() { } 91951a39d68df598db08dfced8b4707755864a0492Ying Wang 92951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 93951a39d68df598db08dfced8b4707755864a0492Ying Wang map(map&& __x) 94951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(std::forward<map>(__x)), _Safe_base() 95951a39d68df598db08dfced8b4707755864a0492Ying Wang { this->_M_swap(__x); } 96951a39d68df598db08dfced8b4707755864a0492Ying Wang 97951a39d68df598db08dfced8b4707755864a0492Ying Wang map(initializer_list<value_type> __l, 98951a39d68df598db08dfced8b4707755864a0492Ying Wang const _Compare& __c = _Compare(), 99951a39d68df598db08dfced8b4707755864a0492Ying Wang const allocator_type& __a = allocator_type()) 100951a39d68df598db08dfced8b4707755864a0492Ying Wang : _Base(__l, __c, __a), _Safe_base() { } 101951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 102951a39d68df598db08dfced8b4707755864a0492Ying Wang 103951a39d68df598db08dfced8b4707755864a0492Ying Wang ~map() { } 104951a39d68df598db08dfced8b4707755864a0492Ying Wang 105951a39d68df598db08dfced8b4707755864a0492Ying Wang map& 106951a39d68df598db08dfced8b4707755864a0492Ying Wang operator=(const map& __x) 107951a39d68df598db08dfced8b4707755864a0492Ying Wang { 108951a39d68df598db08dfced8b4707755864a0492Ying Wang *static_cast<_Base*>(this) = __x; 109951a39d68df598db08dfced8b4707755864a0492Ying Wang this->_M_invalidate_all(); 110951a39d68df598db08dfced8b4707755864a0492Ying Wang return *this; 111951a39d68df598db08dfced8b4707755864a0492Ying Wang } 112951a39d68df598db08dfced8b4707755864a0492Ying Wang 113951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 114951a39d68df598db08dfced8b4707755864a0492Ying Wang map& 115951a39d68df598db08dfced8b4707755864a0492Ying Wang operator=(map&& __x) 116951a39d68df598db08dfced8b4707755864a0492Ying Wang { 117951a39d68df598db08dfced8b4707755864a0492Ying Wang // NB: DR 675. 118951a39d68df598db08dfced8b4707755864a0492Ying Wang clear(); 119951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(__x); 120951a39d68df598db08dfced8b4707755864a0492Ying Wang return *this; 121951a39d68df598db08dfced8b4707755864a0492Ying Wang } 122951a39d68df598db08dfced8b4707755864a0492Ying Wang 123951a39d68df598db08dfced8b4707755864a0492Ying Wang map& 124951a39d68df598db08dfced8b4707755864a0492Ying Wang operator=(initializer_list<value_type> __l) 125951a39d68df598db08dfced8b4707755864a0492Ying Wang { 126951a39d68df598db08dfced8b4707755864a0492Ying Wang this->clear(); 127951a39d68df598db08dfced8b4707755864a0492Ying Wang this->insert(__l); 128951a39d68df598db08dfced8b4707755864a0492Ying Wang return *this; 129951a39d68df598db08dfced8b4707755864a0492Ying Wang } 130951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 131951a39d68df598db08dfced8b4707755864a0492Ying Wang 132951a39d68df598db08dfced8b4707755864a0492Ying Wang // _GLIBCXX_RESOLVE_LIB_DEFECTS 133951a39d68df598db08dfced8b4707755864a0492Ying Wang // 133. map missing get_allocator() 134951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::get_allocator; 135951a39d68df598db08dfced8b4707755864a0492Ying Wang 136951a39d68df598db08dfced8b4707755864a0492Ying Wang // iterators: 137951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 138951a39d68df598db08dfced8b4707755864a0492Ying Wang begin() 139951a39d68df598db08dfced8b4707755864a0492Ying Wang { return iterator(_Base::begin(), this); } 140951a39d68df598db08dfced8b4707755864a0492Ying Wang 141951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 142951a39d68df598db08dfced8b4707755864a0492Ying Wang begin() const 143951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::begin(), this); } 144951a39d68df598db08dfced8b4707755864a0492Ying Wang 145951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 146951a39d68df598db08dfced8b4707755864a0492Ying Wang end() 147951a39d68df598db08dfced8b4707755864a0492Ying Wang { return iterator(_Base::end(), this); } 148951a39d68df598db08dfced8b4707755864a0492Ying Wang 149951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 150951a39d68df598db08dfced8b4707755864a0492Ying Wang end() const 151951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::end(), this); } 152951a39d68df598db08dfced8b4707755864a0492Ying Wang 153951a39d68df598db08dfced8b4707755864a0492Ying Wang reverse_iterator 154951a39d68df598db08dfced8b4707755864a0492Ying Wang rbegin() 155951a39d68df598db08dfced8b4707755864a0492Ying Wang { return reverse_iterator(end()); } 156951a39d68df598db08dfced8b4707755864a0492Ying Wang 157951a39d68df598db08dfced8b4707755864a0492Ying Wang const_reverse_iterator 158951a39d68df598db08dfced8b4707755864a0492Ying Wang rbegin() const 159951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_reverse_iterator(end()); } 160951a39d68df598db08dfced8b4707755864a0492Ying Wang 161951a39d68df598db08dfced8b4707755864a0492Ying Wang reverse_iterator 162951a39d68df598db08dfced8b4707755864a0492Ying Wang rend() 163951a39d68df598db08dfced8b4707755864a0492Ying Wang { return reverse_iterator(begin()); } 164951a39d68df598db08dfced8b4707755864a0492Ying Wang 165951a39d68df598db08dfced8b4707755864a0492Ying Wang const_reverse_iterator 166951a39d68df598db08dfced8b4707755864a0492Ying Wang rend() const 167951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_reverse_iterator(begin()); } 168951a39d68df598db08dfced8b4707755864a0492Ying Wang 169951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 170951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 171951a39d68df598db08dfced8b4707755864a0492Ying Wang cbegin() const 172951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::begin(), this); } 173951a39d68df598db08dfced8b4707755864a0492Ying Wang 174951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 175951a39d68df598db08dfced8b4707755864a0492Ying Wang cend() const 176951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::end(), this); } 177951a39d68df598db08dfced8b4707755864a0492Ying Wang 178951a39d68df598db08dfced8b4707755864a0492Ying Wang const_reverse_iterator 179951a39d68df598db08dfced8b4707755864a0492Ying Wang crbegin() const 180951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_reverse_iterator(end()); } 181951a39d68df598db08dfced8b4707755864a0492Ying Wang 182951a39d68df598db08dfced8b4707755864a0492Ying Wang const_reverse_iterator 183951a39d68df598db08dfced8b4707755864a0492Ying Wang crend() const 184951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_reverse_iterator(begin()); } 185951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 186951a39d68df598db08dfced8b4707755864a0492Ying Wang 187951a39d68df598db08dfced8b4707755864a0492Ying Wang // capacity: 188951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::empty; 189951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::size; 190951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::max_size; 191951a39d68df598db08dfced8b4707755864a0492Ying Wang 192951a39d68df598db08dfced8b4707755864a0492Ying Wang // 23.3.1.2 element access: 193951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::operator[]; 194951a39d68df598db08dfced8b4707755864a0492Ying Wang 195951a39d68df598db08dfced8b4707755864a0492Ying Wang // _GLIBCXX_RESOLVE_LIB_DEFECTS 196951a39d68df598db08dfced8b4707755864a0492Ying Wang // DR 464. Suggestion for new member functions in standard containers. 197951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::at; 198951a39d68df598db08dfced8b4707755864a0492Ying Wang 199951a39d68df598db08dfced8b4707755864a0492Ying Wang // modifiers: 200951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<iterator, bool> 201951a39d68df598db08dfced8b4707755864a0492Ying Wang insert(const value_type& __x) 202951a39d68df598db08dfced8b4707755864a0492Ying Wang { 203951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::iterator _Base_iterator; 204951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<_Base_iterator, bool> __res = _Base::insert(__x); 205951a39d68df598db08dfced8b4707755864a0492Ying Wang return std::pair<iterator, bool>(iterator(__res.first, this), 206951a39d68df598db08dfced8b4707755864a0492Ying Wang __res.second); 207951a39d68df598db08dfced8b4707755864a0492Ying Wang } 208951a39d68df598db08dfced8b4707755864a0492Ying Wang 209951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 210951a39d68df598db08dfced8b4707755864a0492Ying Wang void 211951a39d68df598db08dfced8b4707755864a0492Ying Wang insert(std::initializer_list<value_type> __list) 212951a39d68df598db08dfced8b4707755864a0492Ying Wang { _Base::insert(__list); } 213951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 214951a39d68df598db08dfced8b4707755864a0492Ying Wang 215951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 216951a39d68df598db08dfced8b4707755864a0492Ying Wang insert(iterator __position, const value_type& __x) 217951a39d68df598db08dfced8b4707755864a0492Ying Wang { 218951a39d68df598db08dfced8b4707755864a0492Ying Wang __glibcxx_check_insert(__position); 219951a39d68df598db08dfced8b4707755864a0492Ying Wang return iterator(_Base::insert(__position.base(), __x), this); 220951a39d68df598db08dfced8b4707755864a0492Ying Wang } 221951a39d68df598db08dfced8b4707755864a0492Ying Wang 222951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _InputIterator> 223951a39d68df598db08dfced8b4707755864a0492Ying Wang void 224951a39d68df598db08dfced8b4707755864a0492Ying Wang insert(_InputIterator __first, _InputIterator __last) 225951a39d68df598db08dfced8b4707755864a0492Ying Wang { 226951a39d68df598db08dfced8b4707755864a0492Ying Wang __glibcxx_check_valid_range(__first, __last); 227951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::insert(__first, __last); 228951a39d68df598db08dfced8b4707755864a0492Ying Wang } 229951a39d68df598db08dfced8b4707755864a0492Ying Wang 230951a39d68df598db08dfced8b4707755864a0492Ying Wang void 231951a39d68df598db08dfced8b4707755864a0492Ying Wang erase(iterator __position) 232951a39d68df598db08dfced8b4707755864a0492Ying Wang { 233951a39d68df598db08dfced8b4707755864a0492Ying Wang __glibcxx_check_erase(__position); 234951a39d68df598db08dfced8b4707755864a0492Ying Wang __position._M_invalidate(); 235951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::erase(__position.base()); 236951a39d68df598db08dfced8b4707755864a0492Ying Wang } 237951a39d68df598db08dfced8b4707755864a0492Ying Wang 238951a39d68df598db08dfced8b4707755864a0492Ying Wang size_type 239951a39d68df598db08dfced8b4707755864a0492Ying Wang erase(const key_type& __x) 240951a39d68df598db08dfced8b4707755864a0492Ying Wang { 241951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator __victim = find(__x); 242951a39d68df598db08dfced8b4707755864a0492Ying Wang if (__victim == end()) 243951a39d68df598db08dfced8b4707755864a0492Ying Wang return 0; 244951a39d68df598db08dfced8b4707755864a0492Ying Wang else 245951a39d68df598db08dfced8b4707755864a0492Ying Wang { 246951a39d68df598db08dfced8b4707755864a0492Ying Wang __victim._M_invalidate(); 247951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::erase(__victim.base()); 248951a39d68df598db08dfced8b4707755864a0492Ying Wang return 1; 249951a39d68df598db08dfced8b4707755864a0492Ying Wang } 250951a39d68df598db08dfced8b4707755864a0492Ying Wang } 251951a39d68df598db08dfced8b4707755864a0492Ying Wang 252951a39d68df598db08dfced8b4707755864a0492Ying Wang void 253951a39d68df598db08dfced8b4707755864a0492Ying Wang erase(iterator __first, iterator __last) 254951a39d68df598db08dfced8b4707755864a0492Ying Wang { 255951a39d68df598db08dfced8b4707755864a0492Ying Wang // _GLIBCXX_RESOLVE_LIB_DEFECTS 256951a39d68df598db08dfced8b4707755864a0492Ying Wang // 151. can't currently clear() empty container 257951a39d68df598db08dfced8b4707755864a0492Ying Wang __glibcxx_check_erase_range(__first, __last); 258951a39d68df598db08dfced8b4707755864a0492Ying Wang while (__first != __last) 259951a39d68df598db08dfced8b4707755864a0492Ying Wang this->erase(__first++); 260951a39d68df598db08dfced8b4707755864a0492Ying Wang } 261951a39d68df598db08dfced8b4707755864a0492Ying Wang 262951a39d68df598db08dfced8b4707755864a0492Ying Wang void 263951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 264951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(map&& __x) 265951a39d68df598db08dfced8b4707755864a0492Ying Wang#else 266951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(map& __x) 267951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 268951a39d68df598db08dfced8b4707755864a0492Ying Wang { 269951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::swap(__x); 270951a39d68df598db08dfced8b4707755864a0492Ying Wang this->_M_swap(__x); 271951a39d68df598db08dfced8b4707755864a0492Ying Wang } 272951a39d68df598db08dfced8b4707755864a0492Ying Wang 273951a39d68df598db08dfced8b4707755864a0492Ying Wang void 274951a39d68df598db08dfced8b4707755864a0492Ying Wang clear() 275951a39d68df598db08dfced8b4707755864a0492Ying Wang { this->erase(begin(), end()); } 276951a39d68df598db08dfced8b4707755864a0492Ying Wang 277951a39d68df598db08dfced8b4707755864a0492Ying Wang // observers: 278951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::key_comp; 279951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::value_comp; 280951a39d68df598db08dfced8b4707755864a0492Ying Wang 281951a39d68df598db08dfced8b4707755864a0492Ying Wang // 23.3.1.3 map operations: 282951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 283951a39d68df598db08dfced8b4707755864a0492Ying Wang find(const key_type& __x) 284951a39d68df598db08dfced8b4707755864a0492Ying Wang { return iterator(_Base::find(__x), this); } 285951a39d68df598db08dfced8b4707755864a0492Ying Wang 286951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 287951a39d68df598db08dfced8b4707755864a0492Ying Wang find(const key_type& __x) const 288951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::find(__x), this); } 289951a39d68df598db08dfced8b4707755864a0492Ying Wang 290951a39d68df598db08dfced8b4707755864a0492Ying Wang using _Base::count; 291951a39d68df598db08dfced8b4707755864a0492Ying Wang 292951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 293951a39d68df598db08dfced8b4707755864a0492Ying Wang lower_bound(const key_type& __x) 294951a39d68df598db08dfced8b4707755864a0492Ying Wang { return iterator(_Base::lower_bound(__x), this); } 295951a39d68df598db08dfced8b4707755864a0492Ying Wang 296951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 297951a39d68df598db08dfced8b4707755864a0492Ying Wang lower_bound(const key_type& __x) const 298951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::lower_bound(__x), this); } 299951a39d68df598db08dfced8b4707755864a0492Ying Wang 300951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator 301951a39d68df598db08dfced8b4707755864a0492Ying Wang upper_bound(const key_type& __x) 302951a39d68df598db08dfced8b4707755864a0492Ying Wang { return iterator(_Base::upper_bound(__x), this); } 303951a39d68df598db08dfced8b4707755864a0492Ying Wang 304951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator 305951a39d68df598db08dfced8b4707755864a0492Ying Wang upper_bound(const key_type& __x) const 306951a39d68df598db08dfced8b4707755864a0492Ying Wang { return const_iterator(_Base::upper_bound(__x), this); } 307951a39d68df598db08dfced8b4707755864a0492Ying Wang 308951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<iterator,iterator> 309951a39d68df598db08dfced8b4707755864a0492Ying Wang equal_range(const key_type& __x) 310951a39d68df598db08dfced8b4707755864a0492Ying Wang { 311951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::iterator _Base_iterator; 312951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<_Base_iterator, _Base_iterator> __res = 313951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::equal_range(__x); 314951a39d68df598db08dfced8b4707755864a0492Ying Wang return std::make_pair(iterator(__res.first, this), 315951a39d68df598db08dfced8b4707755864a0492Ying Wang iterator(__res.second, this)); 316951a39d68df598db08dfced8b4707755864a0492Ying Wang } 317951a39d68df598db08dfced8b4707755864a0492Ying Wang 318951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<const_iterator,const_iterator> 319951a39d68df598db08dfced8b4707755864a0492Ying Wang equal_range(const key_type& __x) const 320951a39d68df598db08dfced8b4707755864a0492Ying Wang { 321951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::const_iterator _Base_const_iterator; 322951a39d68df598db08dfced8b4707755864a0492Ying Wang std::pair<_Base_const_iterator, _Base_const_iterator> __res = 323951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base::equal_range(__x); 324951a39d68df598db08dfced8b4707755864a0492Ying Wang return std::make_pair(const_iterator(__res.first, this), 325951a39d68df598db08dfced8b4707755864a0492Ying Wang const_iterator(__res.second, this)); 326951a39d68df598db08dfced8b4707755864a0492Ying Wang } 327951a39d68df598db08dfced8b4707755864a0492Ying Wang 328951a39d68df598db08dfced8b4707755864a0492Ying Wang _Base& 329951a39d68df598db08dfced8b4707755864a0492Ying Wang _M_base() { return *this; } 330951a39d68df598db08dfced8b4707755864a0492Ying Wang 331951a39d68df598db08dfced8b4707755864a0492Ying Wang const _Base& 332951a39d68df598db08dfced8b4707755864a0492Ying Wang _M_base() const { return *this; } 333951a39d68df598db08dfced8b4707755864a0492Ying Wang 334951a39d68df598db08dfced8b4707755864a0492Ying Wang private: 335951a39d68df598db08dfced8b4707755864a0492Ying Wang void 336951a39d68df598db08dfced8b4707755864a0492Ying Wang _M_invalidate_all() 337951a39d68df598db08dfced8b4707755864a0492Ying Wang { 338951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef typename _Base::const_iterator _Base_const_iterator; 339951a39d68df598db08dfced8b4707755864a0492Ying Wang typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal; 340951a39d68df598db08dfced8b4707755864a0492Ying Wang this->_M_invalidate_if(_Not_equal(_M_base().end())); 341951a39d68df598db08dfced8b4707755864a0492Ying Wang } 342951a39d68df598db08dfced8b4707755864a0492Ying Wang }; 343951a39d68df598db08dfced8b4707755864a0492Ying Wang 344951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 345951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 346951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 347951a39d68df598db08dfced8b4707755864a0492Ying Wang operator==(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 348951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 349951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() == __rhs._M_base(); } 350951a39d68df598db08dfced8b4707755864a0492Ying Wang 351951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 352951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 353951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 354951a39d68df598db08dfced8b4707755864a0492Ying Wang operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 355951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 356951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() != __rhs._M_base(); } 357951a39d68df598db08dfced8b4707755864a0492Ying Wang 358951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 359951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 360951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 361951a39d68df598db08dfced8b4707755864a0492Ying Wang operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 362951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 363951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() < __rhs._M_base(); } 364951a39d68df598db08dfced8b4707755864a0492Ying Wang 365951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 366951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 367951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 368951a39d68df598db08dfced8b4707755864a0492Ying Wang operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 369951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 370951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() <= __rhs._M_base(); } 371951a39d68df598db08dfced8b4707755864a0492Ying Wang 372951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 373951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 374951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 375951a39d68df598db08dfced8b4707755864a0492Ying Wang operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 376951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 377951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() >= __rhs._M_base(); } 378951a39d68df598db08dfced8b4707755864a0492Ying Wang 379951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 380951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 381951a39d68df598db08dfced8b4707755864a0492Ying Wang inline bool 382951a39d68df598db08dfced8b4707755864a0492Ying Wang operator>(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, 383951a39d68df598db08dfced8b4707755864a0492Ying Wang const map<_Key, _Tp, _Compare, _Allocator>& __rhs) 384951a39d68df598db08dfced8b4707755864a0492Ying Wang { return __lhs._M_base() > __rhs._M_base(); } 385951a39d68df598db08dfced8b4707755864a0492Ying Wang 386951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 387951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 388951a39d68df598db08dfced8b4707755864a0492Ying Wang inline void 389951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs, 390951a39d68df598db08dfced8b4707755864a0492Ying Wang map<_Key, _Tp, _Compare, _Allocator>& __rhs) 391951a39d68df598db08dfced8b4707755864a0492Ying Wang { __lhs.swap(__rhs); } 392951a39d68df598db08dfced8b4707755864a0492Ying Wang 393951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifdef __GXX_EXPERIMENTAL_CXX0X__ 394951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 395951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 396951a39d68df598db08dfced8b4707755864a0492Ying Wang inline void 397951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(map<_Key, _Tp, _Compare, _Allocator>&& __lhs, 398951a39d68df598db08dfced8b4707755864a0492Ying Wang map<_Key, _Tp, _Compare, _Allocator>& __rhs) 399951a39d68df598db08dfced8b4707755864a0492Ying Wang { __lhs.swap(__rhs); } 400951a39d68df598db08dfced8b4707755864a0492Ying Wang 401951a39d68df598db08dfced8b4707755864a0492Ying Wang template<typename _Key, typename _Tp, 402951a39d68df598db08dfced8b4707755864a0492Ying Wang typename _Compare, typename _Allocator> 403951a39d68df598db08dfced8b4707755864a0492Ying Wang inline void 404951a39d68df598db08dfced8b4707755864a0492Ying Wang swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs, 405951a39d68df598db08dfced8b4707755864a0492Ying Wang map<_Key, _Tp, _Compare, _Allocator>&& __rhs) 406951a39d68df598db08dfced8b4707755864a0492Ying Wang { __lhs.swap(__rhs); } 407951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 408951a39d68df598db08dfced8b4707755864a0492Ying Wang 409951a39d68df598db08dfced8b4707755864a0492Ying Wang} // namespace __debug 410951a39d68df598db08dfced8b4707755864a0492Ying Wang} // namespace std 411951a39d68df598db08dfced8b4707755864a0492Ying Wang 412951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 413