Merge from trunk @ 138209
[official-gcc.git] / libstdc++-v3 / include / debug / unordered_map
blob79590f56755e0bd49d6d03a5d9fba9ef6589a8d4
1 // Debugging unordered_map/unordered_multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
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 /** @file debug/unordered_map
32  *  This file is a GNU debug extension to the Standard C++ Library.
33  */
35 #ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
36 #define _GLIBCXX_DEBUG_UNORDERED_MAP 1
38 #ifdef __GXX_EXPERIMENTAL_CXX0X__
39 # include <unordered_map>
40 #else
41 # include <c++0x_warning.h>
42 #endif
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
50 namespace std
52 namespace __debug
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> >
58     class unordered_map
59     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
60       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
61     {
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;
66     public:
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;
73       explicit
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)
79       { }
81       template<typename _InputIterator>
82         unordered_map(_InputIterator __f, _InputIterator __l, 
83                       size_type __n = 10,
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)
88         { }
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,
97                     size_type __n = 10,
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) { }
103       unordered_map&
104       operator=(unordered_map&& __x)
105       {
106         // NB: DR 675.
107         clear();
108         swap(__x);
109         return *this;
110       }
112       unordered_map&
113       operator=(initializer_list<value_type> __l)
114       {
115         this->clear();
116         this->insert(__l);
117         return *this;
118       }
120       void
121       swap(unordered_map&& __x)
122       {
123         _Safe_assoc::swap(__x);
124         _Safe_base::_M_swap(__x);
125       }
127       void
128       clear()
129       {
130         _Base::clear();
131         this->_M_invalidate_all();
132       }
134     private:
135       void
136       _M_invalidate_all()
137       {
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()));
141       }
142     };
144   template<typename _Key, typename _Tp, typename _Hash,
145            typename _Pred, typename _Alloc>
146     inline void
147     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
148          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
149     { __x.swap(__y); }
151   template<typename _Key, typename _Tp, typename _Hash,
152            typename _Pred, typename _Alloc>
153     inline void
154     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
155          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
156     { __x.swap(__y); }
158   template<typename _Key, typename _Tp, typename _Hash,
159            typename _Pred, typename _Alloc>
160     inline void
161     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
162          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
163     { __x.swap(__y); }
165 #undef _GLIBCXX_BASE
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>
177     {
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;
182     public:
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;
189       explicit
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)
195       { }
197       template<typename _InputIterator>
198         unordered_multimap(_InputIterator __f, _InputIterator __l, 
199                       size_type __n = 10,
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)
204         { }
206       unordered_multimap(initializer_list<value_type> __l,
207                          size_type __n = 10,
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() { }
219       unordered_multimap&
220       operator=(unordered_multimap&& __x)
221       {
222         // NB: DR 675.
223         clear();
224         swap(__x);
225         return *this;
226       }
228       unordered_multimap&
229       operator=(initializer_list<value_type> __l)
230       {
231         this->clear();
232         this->insert(__l);
233         return *this;
234       }
236       void
237       swap(unordered_multimap&& __x)
238       {
239         _Safe_assoc::swap(__x);
240         _Safe_base::_M_swap(__x);
241       }
243       void
244       clear()
245       {
246         _Base::clear();
247         this->_M_invalidate_all();
248       }
250     private:
251       void
252       _M_invalidate_all()
253       {
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()));
257       }
258     };
260   template<typename _Key, typename _Tp, typename _Hash,
261            typename _Pred, typename _Alloc>
262     inline void
263     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
264          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
265     { __x.swap(__y); }
267   template<typename _Key, typename _Tp, typename _Hash,
268            typename _Pred, typename _Alloc>
269     inline void
270     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
271          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
272     { __x.swap(__y); }
274   template<typename _Key, typename _Tp, typename _Hash,
275            typename _Pred, typename _Alloc>
276     inline void
277     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
278          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
279     { __x.swap(__y); }
281 } // namespace __debug
282 } // namespace std
284 #undef _GLIBCXX_BASE
285 #undef _GLIBCXX_STD_BASE
287 #endif