OSDN Git Service

4f914495ddb7aa5d6588bf7237be3c161332b366
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1_impl / unordered_map
1 // TR1 unordered_map -*- C++ -*-
2
3 // Copyright (C) 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file tr1_impl/unordered_map
31  *  This is an internal header file, included by other library headers.
32  *  You should not attempt to use it directly.
33  */
34
35 namespace std
36 {
37 _GLIBCXX_BEGIN_NAMESPACE_TR1
38
39   // XXX When we get typedef templates these class definitions
40   // will be unnecessary.
41   template<class _Key, class _Tp,
42            class _Hash = hash<_Key>,
43            class _Pred = std::equal_to<_Key>,
44            class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
45            bool __cache_hash_code = false>
46     class __unordered_map
47     : public _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
48                         std::_Select1st<std::pair<const _Key, _Tp> >, _Pred, 
49                         _Hash, __detail::_Mod_range_hashing,
50                         __detail::_Default_ranged_hash,
51                         __detail::_Prime_rehash_policy,
52                         __cache_hash_code, false, true>
53     {
54       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
55                          std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
56                          _Hash, __detail::_Mod_range_hashing,
57                          __detail::_Default_ranged_hash,
58                          __detail::_Prime_rehash_policy,
59                          __cache_hash_code, false, true>
60         _Base;
61
62     public:
63       typedef typename _Base::size_type       size_type;
64       typedef typename _Base::hasher          hasher;
65       typedef typename _Base::key_equal       key_equal;
66       typedef typename _Base::allocator_type  allocator_type;
67
68       explicit
69       __unordered_map(size_type __n = 10,
70                       const hasher& __hf = hasher(),
71                       const key_equal& __eql = key_equal(),
72                       const allocator_type& __a = allocator_type())
73       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
74               __detail::_Default_ranged_hash(),
75               __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
76       { }
77
78       template<typename _InputIterator>
79         __unordered_map(_InputIterator __f, _InputIterator __l, 
80                         size_type __n = 10,
81                         const hasher& __hf = hasher(), 
82                         const key_equal& __eql = key_equal(), 
83                         const allocator_type& __a = allocator_type())
84         : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
85                 __detail::_Default_ranged_hash(),
86                 __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
87         { }
88
89 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
90       __unordered_map(__unordered_map&& __x)
91       : _Base(std::forward<_Base>(__x)) { }
92 #endif
93     };
94   
95   template<class _Key, class _Tp,
96            class _Hash = hash<_Key>,
97            class _Pred = std::equal_to<_Key>,
98            class _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
99            bool __cache_hash_code = false>
100     class __unordered_multimap
101     : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
102                         _Alloc,
103                         std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
104                         _Hash, __detail::_Mod_range_hashing,
105                         __detail::_Default_ranged_hash,
106                         __detail::_Prime_rehash_policy,
107                         __cache_hash_code, false, false>
108     {
109       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
110                          _Alloc,
111                          std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
112                          _Hash, __detail::_Mod_range_hashing,
113                          __detail::_Default_ranged_hash,
114                          __detail::_Prime_rehash_policy,
115                          __cache_hash_code, false, false>
116         _Base;
117
118     public:
119       typedef typename _Base::size_type       size_type;
120       typedef typename _Base::hasher          hasher;
121       typedef typename _Base::key_equal       key_equal;
122       typedef typename _Base::allocator_type  allocator_type;
123       
124       explicit
125       __unordered_multimap(size_type __n = 10,
126                            const hasher& __hf = hasher(),
127                            const key_equal& __eql = key_equal(),
128                            const allocator_type& __a = allocator_type())
129       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
130               __detail::_Default_ranged_hash(),
131               __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
132       { }
133
134
135       template<typename _InputIterator>
136         __unordered_multimap(_InputIterator __f, _InputIterator __l, 
137                              typename _Base::size_type __n = 0,
138                              const hasher& __hf = hasher(), 
139                              const key_equal& __eql = key_equal(), 
140                              const allocator_type& __a = allocator_type())
141         : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
142                 __detail::_Default_ranged_hash(),
143                 __eql, std::_Select1st<std::pair<const _Key, _Tp> >(), __a)
144         { }
145
146 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
147       __unordered_multimap(__unordered_multimap&& __x)
148       : _Base(std::forward<_Base>(__x)) { }
149 #endif
150     };
151
152   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
153            bool __cache_hash_code>
154     inline void
155     swap(__unordered_map<_Key, _Tp, _Hash, _Pred,
156          _Alloc, __cache_hash_code>& __x,
157          __unordered_map<_Key, _Tp, _Hash, _Pred,
158          _Alloc, __cache_hash_code>& __y)
159     { __x.swap(__y); }
160
161   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
162            bool __cache_hash_code>
163     inline void
164     swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred,
165          _Alloc, __cache_hash_code>& __x,
166          __unordered_multimap<_Key, _Tp, _Hash, _Pred,
167          _Alloc, __cache_hash_code>& __y)
168     { __x.swap(__y); }
169
170
171   /// class unordered_map
172   template<class _Key, class _Tp,
173            class _Hash = hash<_Key>,
174            class _Pred = std::equal_to<_Key>,
175            class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
176     class unordered_map
177     : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
178     {
179       typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
180
181     public:
182       typedef typename _Base::value_type      value_type;
183       typedef typename _Base::size_type       size_type;
184       typedef typename _Base::hasher          hasher;
185       typedef typename _Base::key_equal       key_equal;
186       typedef typename _Base::allocator_type  allocator_type;
187
188       explicit
189       unordered_map(size_type __n = 10,
190                     const hasher& __hf = hasher(),
191                     const key_equal& __eql = key_equal(),
192                     const allocator_type& __a = allocator_type())
193       : _Base(__n, __hf, __eql, __a)
194       { }
195
196       template<typename _InputIterator>
197         unordered_map(_InputIterator __f, _InputIterator __l, 
198                       size_type __n = 10,
199                       const hasher& __hf = hasher(), 
200                       const key_equal& __eql = key_equal(), 
201                       const allocator_type& __a = allocator_type())
202         : _Base(__f, __l, __n, __hf, __eql, __a)
203         { }
204
205 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
206       unordered_map(unordered_map&& __x)
207       : _Base(std::forward<_Base>(__x)) { }
208
209       unordered_map(initializer_list<value_type> __l,
210                     size_type __n = 10,
211                     const hasher& __hf = hasher(),
212                     const key_equal& __eql = key_equal(),
213                     const allocator_type& __a = allocator_type())
214         : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
215       { }
216
217       unordered_map&
218       operator=(unordered_map&& __x)
219       {
220         // NB: DR 675.
221         this->clear();
222         this->swap(__x); 
223         return *this;   
224       }
225
226       unordered_map&
227       operator=(initializer_list<value_type> __l)
228       {
229         this->clear();
230         this->insert(__l.begin(), __l.end());
231         return *this;
232       }
233 #endif
234     };
235   
236   /// class unordered_multimap
237   template<class _Key, class _Tp,
238            class _Hash = hash<_Key>,
239            class _Pred = std::equal_to<_Key>,
240            class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
241     class unordered_multimap
242     : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
243     {
244       typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>  _Base;
245
246     public:
247       typedef typename _Base::value_type      value_type;
248       typedef typename _Base::size_type       size_type;
249       typedef typename _Base::hasher          hasher;
250       typedef typename _Base::key_equal       key_equal;
251       typedef typename _Base::allocator_type  allocator_type;
252       
253       explicit
254       unordered_multimap(size_type __n = 10,
255                          const hasher& __hf = hasher(),
256                          const key_equal& __eql = key_equal(),
257                          const allocator_type& __a = allocator_type())
258       : _Base(__n, __hf, __eql, __a)
259       { }
260
261
262       template<typename _InputIterator>
263         unordered_multimap(_InputIterator __f, _InputIterator __l, 
264                            typename _Base::size_type __n = 0,
265                            const hasher& __hf = hasher(), 
266                            const key_equal& __eql = key_equal(), 
267                            const allocator_type& __a = allocator_type())
268         : _Base(__f, __l, __n, __hf, __eql, __a)
269         { }
270
271 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
272       unordered_multimap(unordered_multimap&& __x)
273       : _Base(std::forward<_Base>(__x)) { }
274
275       unordered_multimap(initializer_list<value_type> __l,
276                          size_type __n = 10,
277                          const hasher& __hf = hasher(),
278                          const key_equal& __eql = key_equal(),
279                          const allocator_type& __a = allocator_type())
280         : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
281       { }
282
283       unordered_multimap&
284       operator=(unordered_multimap&& __x)
285       {
286         // NB: DR 675.
287         this->clear();
288         this->swap(__x); 
289         return *this;   
290       }
291
292       unordered_multimap&
293       operator=(initializer_list<value_type> __l)
294       {
295         this->clear();
296         this->insert(__l.begin(), __l.end());
297         return *this;
298       }
299 #endif
300     };
301
302   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
303     inline void
304     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
305          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
306     { __x.swap(__y); }
307
308   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
309     inline void
310     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
311          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
312     { __x.swap(__y); }
313
314 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
315   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
316     inline void
317     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
318          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
319     { __x.swap(__y); }
320
321   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
322     inline void
323     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
324          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
325     { __x.swap(__y); }
326
327   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
328     inline void
329     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
330          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
331     { __x.swap(__y); }
332
333   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
334     inline void
335     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
336          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
337     { __x.swap(__y); }
338 #endif
339
340 _GLIBCXX_END_NAMESPACE_TR1
341 }