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 <debug/safe_association.h>
44 #include <debug/safe_iterator.h>
46 #define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
47 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
53 template<typename _Key, typename _Tp,
54 typename _Hash = std::hash<_Key>,
55 typename _Pred = std::equal_to<_Key>,
56 typename _Alloc = std::allocator<_Key> >
58 : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
59 public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
61 typedef typename _GLIBCXX_STD_BASE _Base;
62 typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
63 typedef __gnu_debug::_Safe_sequence<unordered_map> _Safe_base;
66 typedef typename _Safe_assoc::size_type size_type;
67 typedef typename _Safe_assoc::hasher hasher;
68 typedef typename _Safe_assoc::key_equal key_equal;
69 typedef typename _Safe_assoc::allocator_type allocator_type;
72 unordered_map(size_type __n = 10,
73 const hasher& __hf = hasher(),
74 const key_equal& __eql = key_equal(),
75 const allocator_type& __a = allocator_type())
76 : _Safe_assoc(__n, __hf, __eql, __a)
79 template<typename _InputIterator>
80 unordered_map(_InputIterator __f, _InputIterator __l,
82 const hasher& __hf = hasher(),
83 const key_equal& __eql = key_equal(),
84 const allocator_type& __a = allocator_type())
85 : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
88 unordered_map(const _Safe_assoc& __x)
89 : _Safe_assoc(__x), _Safe_base() { }
91 unordered_map(unordered_map&& __x)
92 : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
95 operator=(unordered_map&& __x)
104 swap(unordered_map&& __x)
106 _Safe_assoc::swap(__x);
107 _Safe_base::_M_swap(__x);
114 this->_M_invalidate_all();
121 typedef typename _Base::const_iterator _Base_const_iterator;
122 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
123 this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
127 template<typename _Key, typename _Tp, typename _Hash,
128 typename _Pred, typename _Alloc>
130 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
131 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
134 template<typename _Key, typename _Tp, typename _Hash,
135 typename _Pred, typename _Alloc>
137 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
138 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
141 template<typename _Key, typename _Tp, typename _Hash,
142 typename _Pred, typename _Alloc>
144 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
145 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
149 #undef _GLIBCXX_STD_BASE
150 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
151 #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
153 template<typename _Key, typename _Tp,
154 typename _Hash = std::hash<_Key>,
155 typename _Pred = std::equal_to<_Key>,
156 typename _Alloc = std::allocator<_Key> >
157 class unordered_multimap
158 : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
159 public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
161 typedef typename _GLIBCXX_STD_BASE _Base;
162 typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
163 typedef __gnu_debug::_Safe_sequence<unordered_multimap> _Safe_base;
166 typedef typename _Safe_assoc::size_type size_type;
167 typedef typename _Safe_assoc::hasher hasher;
168 typedef typename _Safe_assoc::key_equal key_equal;
169 typedef typename _Safe_assoc::allocator_type allocator_type;
172 unordered_multimap(size_type __n = 10,
173 const hasher& __hf = hasher(),
174 const key_equal& __eql = key_equal(),
175 const allocator_type& __a = allocator_type())
176 : _Safe_assoc(__n, __hf, __eql, __a)
179 template<typename _InputIterator>
180 unordered_multimap(_InputIterator __f, _InputIterator __l,
182 const hasher& __hf = hasher(),
183 const key_equal& __eql = key_equal(),
184 const allocator_type& __a = allocator_type())
185 : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
188 unordered_multimap(const _Safe_assoc& __x)
189 : _Safe_assoc(__x), _Safe_base() { }
191 unordered_multimap(unordered_multimap&& __x)
192 : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
195 operator=(unordered_multimap&& __x)
204 swap(unordered_multimap&& __x)
206 _Safe_assoc::swap(__x);
207 _Safe_base::_M_swap(__x);
214 this->_M_invalidate_all();
221 typedef typename _Base::const_iterator _Base_const_iterator;
222 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
223 this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
227 template<typename _Key, typename _Tp, typename _Hash,
228 typename _Pred, typename _Alloc>
230 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
231 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
234 template<typename _Key, typename _Tp, typename _Hash,
235 typename _Pred, typename _Alloc>
237 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
238 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
241 template<typename _Key, typename _Tp, typename _Hash,
242 typename _Pred, typename _Alloc>
244 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
245 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
248 } // namespace __debug
252 #undef _GLIBCXX_STD_BASE