1 // Debugging unordered_map/unordered_multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
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)
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,
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 /** @file debug/unordered_map
32 * This file is a GNU debug extension to the Standard C++ Library.
35 #ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
36 #define _GLIBCXX_DEBUG_UNORDERED_MAP 1
38 #ifdef __GXX_EXPERIMENTAL_CXX0X__
39 # include <unordered_map>
41 # include <c++0x_warning.h>
43 #include <initializer_list>
44 #include <debug/safe_association.h>
45 #include <debug/safe_iterator.h>
47 #define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
48 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
54 template<typename _Key, typename _Tp,
55 typename _Hash = std::hash<_Key>,
56 typename _Pred = std::equal_to<_Key>,
57 typename _Alloc = std::allocator<_Key> >
59 : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
60 public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
62 typedef typename _GLIBCXX_STD_BASE _Base;
63 typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
64 typedef __gnu_debug::_Safe_sequence<unordered_map> _Safe_base;
67 typedef typename _Safe_assoc::size_type size_type;
68 typedef typename _Safe_assoc::value_type value_type;
69 typedef typename _Safe_assoc::hasher hasher;
70 typedef typename _Safe_assoc::key_equal key_equal;
71 typedef typename _Safe_assoc::allocator_type allocator_type;
74 unordered_map(size_type __n = 10,
75 const hasher& __hf = hasher(),
76 const key_equal& __eql = key_equal(),
77 const allocator_type& __a = allocator_type())
78 : _Safe_assoc(__n, __hf, __eql, __a)
81 template<typename _InputIterator>
82 unordered_map(_InputIterator __f, _InputIterator __l,
84 const hasher& __hf = hasher(),
85 const key_equal& __eql = key_equal(),
86 const allocator_type& __a = allocator_type())
87 : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
90 unordered_map(const _Safe_assoc& __x)
91 : _Safe_assoc(__x), _Safe_base() { }
93 unordered_map(unordered_map&& __x)
94 : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
96 unordered_map(initializer_list<value_type> __l,
98 const hasher& __hf = hasher(),
99 const key_equal& __eql = key_equal(),
100 const allocator_type& __a = allocator_type())
101 : _Safe_assoc(__l, __n, __hf, __eql, __a) { }
104 operator=(unordered_map&& __x)
113 operator=(initializer_list<value_type> __l)
121 swap(unordered_map&& __x)
123 _Safe_assoc::swap(__x);
124 _Safe_base::_M_swap(__x);
131 this->_M_invalidate_all();
138 typedef typename _Base::const_iterator _Base_const_iterator;
139 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
140 this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
144 template<typename _Key, typename _Tp, typename _Hash,
145 typename _Pred, typename _Alloc>
147 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
148 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
151 template<typename _Key, typename _Tp, typename _Hash,
152 typename _Pred, typename _Alloc>
154 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
155 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
158 template<typename _Key, typename _Tp, typename _Hash,
159 typename _Pred, typename _Alloc>
161 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
162 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
166 #undef _GLIBCXX_STD_BASE
167 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
168 #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
170 template<typename _Key, typename _Tp,
171 typename _Hash = std::hash<_Key>,
172 typename _Pred = std::equal_to<_Key>,
173 typename _Alloc = std::allocator<_Key> >
174 class unordered_multimap
175 : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
176 public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
178 typedef typename _GLIBCXX_STD_BASE _Base;
179 typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
180 typedef __gnu_debug::_Safe_sequence<unordered_multimap> _Safe_base;
183 typedef typename _Safe_assoc::size_type size_type;
184 typedef typename _Safe_assoc::value_type value_type;
185 typedef typename _Safe_assoc::hasher hasher;
186 typedef typename _Safe_assoc::key_equal key_equal;
187 typedef typename _Safe_assoc::allocator_type allocator_type;
190 unordered_multimap(size_type __n = 10,
191 const hasher& __hf = hasher(),
192 const key_equal& __eql = key_equal(),
193 const allocator_type& __a = allocator_type())
194 : _Safe_assoc(__n, __hf, __eql, __a)
197 template<typename _InputIterator>
198 unordered_multimap(_InputIterator __f, _InputIterator __l,
200 const hasher& __hf = hasher(),
201 const key_equal& __eql = key_equal(),
202 const allocator_type& __a = allocator_type())
203 : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
206 unordered_multimap(initializer_list<value_type> __l,
208 const hasher& __hf = hasher(),
209 const key_equal& __eql = key_equal(),
210 const allocator_type& __a = allocator_type())
211 : _Safe_assoc(__l, __n, __hf, __eql, __a) { }
213 unordered_multimap(const _Safe_assoc& __x)
214 : _Safe_assoc(__x), _Safe_base() { }
216 unordered_multimap(unordered_multimap&& __x)
217 : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
220 operator=(unordered_multimap&& __x)
229 operator=(initializer_list<value_type> __l)
237 swap(unordered_multimap&& __x)
239 _Safe_assoc::swap(__x);
240 _Safe_base::_M_swap(__x);
247 this->_M_invalidate_all();
254 typedef typename _Base::const_iterator _Base_const_iterator;
255 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
256 this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
260 template<typename _Key, typename _Tp, typename _Hash,
261 typename _Pred, typename _Alloc>
263 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
264 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
267 template<typename _Key, typename _Tp, typename _Hash,
268 typename _Pred, typename _Alloc>
270 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
271 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
274 template<typename _Key, typename _Tp, typename _Hash,
275 typename _Pred, typename _Alloc>
277 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
278 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
281 } // namespace __debug
285 #undef _GLIBCXX_STD_BASE