Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / debug / unordered_map
blob590d4a3478f03c772b306469710664b2bdde5ecd
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 <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
49 namespace std
51 namespace __debug
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> >
57     class unordered_map
58     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
59       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
60     {
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;
65     public:
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;
71       explicit
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)
77       { }
79       template<typename _InputIterator>
80         unordered_map(_InputIterator __f, _InputIterator __l, 
81                       size_type __n = 10,
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)
86         { }
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() { }
94       unordered_map&
95       operator=(unordered_map&& __x)
96       {
97         // NB: DR 675.
98         clear();
99         swap(__x);
100         return *this;
101       }
103       void
104       swap(unordered_map&& __x)
105       {
106         _Safe_assoc::swap(__x);
107         _Safe_base::_M_swap(__x);
108       }
110       void
111       clear()
112       {
113         _Base::clear();
114         this->_M_invalidate_all();
115       }
117     private:
118       void
119       _M_invalidate_all()
120       {
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()));
124       }
125     };
127   template<typename _Key, typename _Tp, typename _Hash,
128            typename _Pred, typename _Alloc>
129     inline void
130     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
131          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
132     { __x.swap(__y); }
134   template<typename _Key, typename _Tp, typename _Hash,
135            typename _Pred, typename _Alloc>
136     inline void
137     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
138          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
139     { __x.swap(__y); }
141   template<typename _Key, typename _Tp, typename _Hash,
142            typename _Pred, typename _Alloc>
143     inline void
144     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
145          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
146     { __x.swap(__y); }
148 #undef _GLIBCXX_BASE
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>
160     {
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;
165     public:
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;
171       explicit
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)
177       { }
179       template<typename _InputIterator>
180         unordered_multimap(_InputIterator __f, _InputIterator __l, 
181                       size_type __n = 10,
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)
186         { }
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() { }
194       unordered_multimap&
195       operator=(unordered_multimap&& __x)
196       {
197         // NB: DR 675.
198         clear();
199         swap(__x);
200         return *this;
201       }
203       void
204       swap(unordered_multimap&& __x)
205       {
206         _Safe_assoc::swap(__x);
207         _Safe_base::_M_swap(__x);
208       }
210       void
211       clear()
212       {
213         _Base::clear();
214         this->_M_invalidate_all();
215       }
217     private:
218       void
219       _M_invalidate_all()
220       {
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()));
224       }
225     };
227   template<typename _Key, typename _Tp, typename _Hash,
228            typename _Pred, typename _Alloc>
229     inline void
230     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
231          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
232     { __x.swap(__y); }
234   template<typename _Key, typename _Tp, typename _Hash,
235            typename _Pred, typename _Alloc>
236     inline void
237     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
238          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
239     { __x.swap(__y); }
241   template<typename _Key, typename _Tp, typename _Hash,
242            typename _Pred, typename _Alloc>
243     inline void
244     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
245          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
246     { __x.swap(__y); }
248 } // namespace __debug
249 } // namespace std
251 #undef _GLIBCXX_BASE
252 #undef _GLIBCXX_STD_BASE
254 #endif