* Mainline merge as of 2006-02-16 (@111136).
[official-gcc.git] / libstdc++-v3 / include / debug / hash_multimap.h
blob2073df09d186503e9573ffd523efffeee0ad3b6c
1 // Debugging hash_multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2005, 2006
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #ifndef _GLIBCXX_DEBUG_HASH_MULTIMAP_H
32 #define _GLIBCXX_DEBUG_HASH_MULTIMAP_H 1
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
37 namespace __gnu_cxx
39 namespace __gnu_debug
41 template<typename _Value, typename _Tp,
42 typename _HashFcn = __gnu_cxx::hash<_Value>,
43 typename _EqualKey = std::equal_to<_Value>,
44 typename _Alloc = std::allocator<_Value> >
45 class hash_multimap
46 : public __gnu_cxx::hash_multimap<_Value,_Tp,_HashFcn, _EqualKey,_Alloc>,
47 public __gnu_debug::_Safe_sequence<hash_multimap<_Value, _Tp, _HashFcn,
48 _EqualKey, _Alloc> >
50 typedef __gnu_cxx::hash_multimap<_Value,_Tp,_HashFcn, _EqualKey,_Alloc>
51 _Base;
52 typedef __gnu_debug::_Safe_sequence<hash_multimap> _Safe_base;
54 public:
55 typedef typename _Base::key_type key_type;
56 typedef typename _Base::data_type data_type;
57 typedef typename _Base::mapped_type mapped_type;
58 typedef typename _Base::value_type value_type;
59 typedef typename _Base::hasher hasher;
60 typedef typename _Base::key_equal key_equal;
61 typedef typename _Base::size_type size_type;
62 typedef typename _Base::difference_type difference_type;
63 typedef typename _Base::pointer pointer;
64 typedef typename _Base::const_pointer const_pointer;
65 typedef typename _Base::reference reference;
66 typedef typename _Base::const_reference const_reference;
68 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,
69 hash_multimap> iterator;
70 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
71 hash_multimap> const_iterator;
73 typedef typename _Base::allocator_type allocator_type;
75 using _Base::hash_funct;
76 using _Base::key_eq;
77 using _Base::get_allocator;
79 hash_multimap() { }
81 explicit hash_multimap(size_type __n) : _Base(__n) { }
83 hash_multimap(size_type __n, const hasher& __hf) : _Base(__n, __hf) { }
85 hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
86 const allocator_type& __a = allocator_type())
87 : _Base(__n, __hf, __eql, __a) { }
89 template<typename _InputIterator>
90 hash_multimap(_InputIterator __f, _InputIterator __l)
91 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l) { }
93 template<typename _InputIterator>
94 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
95 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n) { }
97 template<typename _InputIterator>
98 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
99 const hasher& __hf)
100 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf) { }
102 template<typename _InputIterator>
103 hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
104 const hasher& __hf, const key_equal& __eql,
105 const allocator_type& __a = allocator_type())
106 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf,
107 __eql, __a) { }
109 using _Base::size;
110 using _Base::max_size;
111 using _Base::empty;
113 void
114 swap(hash_multimap& __x)
116 _Base::swap(__x);
117 this->_M_swap(__x);
120 iterator
121 begin() { return iterator(_Base::begin(), this); }
123 iterator
124 end() { return iterator(_Base::end(), this); }
126 const_iterator
127 begin() const
128 { return const_iterator(_Base::begin(), this); }
130 const_iterator
131 end() const
132 { return const_iterator(_Base::end(), this); }
134 iterator
135 insert(const value_type& __obj)
136 { return iterator(_Base::insert(__obj), this); }
138 template <typename _InputIterator>
139 void
140 insert(_InputIterator __first, _InputIterator __last)
142 __glibcxx_check_valid_range(__first, __last);
143 _Base::insert(__first.base(), __last.base());
146 iterator
147 insert_noresize(const value_type& __obj)
148 { return iterator(_Base::insert_noresize(__obj), this); }
150 iterator
151 find(const key_type& __key)
152 { return iterator(_Base::find(__key), this); }
154 const_iterator
155 find(const key_type& __key) const
156 { return const_iterator(_Base::find(__key), this); }
158 using _Base::count;
160 std::pair<iterator, iterator>
161 equal_range(const key_type& __key)
163 typedef typename _Base::iterator _Base_iterator;
164 std::pair<_Base_iterator, _Base_iterator> __res =
165 _Base::equal_range(__key);
166 return std::make_pair(iterator(__res.first, this),
167 iterator(__res.second, this));
170 std::pair<const_iterator, const_iterator>
171 equal_range(const key_type& __key) const
173 typedef typename _Base::const_iterator _Base_iterator;
174 std::pair<_Base_iterator, _Base_iterator> __res =
175 _Base::equal_range(__key);
176 return std::make_pair(const_iterator(__res.first, this),
177 const_iterator(__res.second, this));
180 size_type
181 erase(const key_type& __key)
183 std::pair<iterator, iterator> __victims = this->equal_range(__key);
184 size_t __num_victims = 0;
185 while (__victims.first != __victims.second)
187 this->erase(__victims.first++);
188 ++__num_victims;
190 return __num_victims;
193 void
194 erase(iterator __it)
196 __glibcxx_check_erase(__it);
197 __it._M_invalidate();
198 _Base::erase(__it.base());
201 void
202 erase(iterator __first, iterator __last)
204 __glibcxx_check_erase_range(__first, __last);
205 for (iterator __tmp = __first; __tmp != __last;)
207 iterator __victim = __tmp++;
208 __victim._M_invalidate();
210 _Base::erase(__first.base(), __last.base());
213 void
214 clear()
216 _Base::clear();
217 this->_M_invalidate_all();
220 using _Base::resize;
221 using _Base::bucket_count;
222 using _Base::max_bucket_count;
223 using _Base::elems_in_bucket;
225 _Base&
226 _M_base() { return *this; }
228 const _Base&
229 _M_base() const { return *this; }
231 private:
232 void
233 _M_invalidate_all()
235 typedef typename _Base::const_iterator _Base_const_iterator;
236 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
237 this->_M_invalidate_if(_Not_equal(_M_base().end()));
241 template<typename _Value, typename _Tp, typename _HashFcn,
242 typename _EqualKey, typename _Alloc>
243 inline bool
244 operator==(const hash_multimap<_Value,_Tp,_HashFcn,_EqualKey,_Alloc>& __x,
245 const hash_multimap<_Value,_Tp,_HashFcn,_EqualKey,_Alloc>& __y)
246 { return __x._M_base() == __y._M_base(); }
248 template<typename _Value, typename _Tp, typename _HashFcn,
249 typename _EqualKey, typename _Alloc>
250 inline bool
251 operator!=(const hash_multimap<_Value,_Tp,_HashFcn,_EqualKey,_Alloc>& __x,
252 const hash_multimap<_Value,_Tp,_HashFcn,_EqualKey,_Alloc>& __y)
253 { return __x._M_base() != __y._M_base(); }
255 template<typename _Value, typename _Tp, typename _HashFcn,
256 typename _EqualKey, typename _Alloc>
257 inline void
258 swap(hash_multimap<_Value, _Tp, _HashFcn, _EqualKey, _Alloc>& __x,
259 hash_multimap<_Value, _Tp, _HashFcn, _EqualKey, _Alloc>& __y)
260 { __x.swap(__y); }
261 } // namespace __gnu_debug
262 } // namespace __gnu_cxx
264 #endif