]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/debug/unordered_map
re PR libstdc++/30085 (switch debug mode hash containers from ext to tr1)
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / unordered_map
1 // Debugging unordered_map/unordered_multimap implementation -*- C++ -*-
2
3 // Copyright (C) 2003, 2005, 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.
11
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.
16
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.
21
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.
30
31 /** @file debug/unordered_map
32 * This file is a GNU debug extension to the Standard C++ Library.
33 */
34
35 #ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
36 #define _GLIBCXX_DEBUG_UNORDERED_MAP 1
37
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>
45
46 #define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
47 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
48
49 namespace std
50 {
51 namespace __debug
52 {
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;
64
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;
70
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 { }
78
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 { }
87
88 unordered_map(const _Safe_assoc& __x)
89 : _Safe_assoc(__x), _Safe_base() { }
90
91 void
92 swap(unordered_map& __x)
93 {
94 _Safe_assoc::swap(__x);
95 _Safe_base::_M_swap(__x);
96 }
97 };
98
99 template<typename _Key, typename _Tp, typename _Hash,
100 typename _Pred, typename _Alloc>
101 inline bool
102 operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
103 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
104 { return __x._M_base() == __y._M_base(); }
105
106 template<typename _Key, typename _Tp, typename _Hash,
107 typename _Pred, typename _Alloc>
108 inline bool
109 operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
110 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
111 { return __x._M_base() != __y._M_base(); }
112
113 template<typename _Key, typename _Tp, typename _Hash,
114 typename _Pred, typename _Alloc>
115 inline void
116 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
117 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
118 { __x.swap(__y); }
119
120 #undef _GLIBCXX_BASE
121 #undef _GLIBCXX_STD_BASE
122 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
123 #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
124
125 template<typename _Key, typename _Tp,
126 typename _Hash = std::hash<_Key>,
127 typename _Pred = std::equal_to<_Key>,
128 typename _Alloc = std::allocator<_Key> >
129 class unordered_multimap
130 : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
131 public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
132 {
133 typedef typename _GLIBCXX_STD_BASE _Base;
134 typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
135 typedef __gnu_debug::_Safe_sequence<unordered_multimap> _Safe_base;
136
137 public:
138 typedef typename _Safe_assoc::size_type size_type;
139 typedef typename _Safe_assoc::hasher hasher;
140 typedef typename _Safe_assoc::key_equal key_equal;
141 typedef typename _Safe_assoc::allocator_type allocator_type;
142
143 explicit
144 unordered_multimap(size_type __n = 10,
145 const hasher& __hf = hasher(),
146 const key_equal& __eql = key_equal(),
147 const allocator_type& __a = allocator_type())
148 : _Safe_assoc(__n, __hf, __eql, __a)
149 { }
150
151 template<typename _InputIterator>
152 unordered_multimap(_InputIterator __f, _InputIterator __l,
153 size_type __n = 10,
154 const hasher& __hf = hasher(),
155 const key_equal& __eql = key_equal(),
156 const allocator_type& __a = allocator_type())
157 : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
158 { }
159
160 unordered_multimap(const _Safe_assoc& __x)
161 : _Safe_assoc(__x), _Safe_base() { }
162
163 void
164 swap(unordered_multimap& __x)
165 {
166 _Safe_assoc::swap(__x);
167 _Safe_base::_M_swap(__x);
168 }
169 };
170
171 template<typename _Key, typename _Tp, typename _Hash,
172 typename _Pred, typename _Alloc>
173 inline bool
174 operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
175 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
176 { return __x._M_base() == __y._M_base(); }
177
178 template<typename _Key, typename _Tp, typename _Hash,
179 typename _Pred, typename _Alloc>
180 inline bool
181 operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
182 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
183 { return __x._M_base() != __y._M_base(); }
184
185 template<typename _Key, typename _Tp, typename _Hash,
186 typename _Pred, typename _Alloc>
187 inline void
188 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
189 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
190 { __x.swap(__y); }
191
192
193 } // namespace __debug
194 } // namespace std
195
196 #undef _GLIBCXX_BASE
197 #undef _GLIBCXX_STD_BASE
198
199 #endif