Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / libstdc++-v3 / include / tr1_impl / unordered_set
blob742b88791c2ba65197bed7f0305cb32a3381d309
1 // TR1 unordered_set -*- C++ -*-
3 // Copyright (C) 2007, 2009 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.
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.
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.
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.
30 /** @file tr1_impl/unordered_set
31  *  This is an internal header file, included by other library headers.
32  *  You should not attempt to use it directly.
33  */
35 namespace std
36
37 _GLIBCXX_BEGIN_NAMESPACE_TR1
39   // XXX When we get typedef templates these class definitions
40   // will be unnecessary.
41   template<class _Value,
42            class _Hash = hash<_Value>,
43            class _Pred = std::equal_to<_Value>,
44            class _Alloc = std::allocator<_Value>,
45            bool __cache_hash_code = false>
46     class __unordered_set
47     : public _Hashtable<_Value, _Value, _Alloc,
48                         std::_Identity<_Value>, _Pred,
49                         _Hash, __detail::_Mod_range_hashing,
50                         __detail::_Default_ranged_hash,
51                         __detail::_Prime_rehash_policy,
52                         __cache_hash_code, true, true>
53     {
54       typedef _Hashtable<_Value, _Value, _Alloc,
55                          std::_Identity<_Value>, _Pred,
56                          _Hash, __detail::_Mod_range_hashing,
57                          __detail::_Default_ranged_hash,
58                          __detail::_Prime_rehash_policy,
59                          __cache_hash_code, true, true>
60         _Base;
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_set(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(), __eql,
75               std::_Identity<_Value>(), __a)
76       { }
78       template<typename _InputIterator>
79         __unordered_set(_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(), __eql,
86                 std::_Identity<_Value>(), __a)
87         { }
89 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
90       __unordered_set(__unordered_set&& __x)
91       : _Base(std::forward<_Base>(__x)) { }
92 #endif
93     };
95   template<class _Value,
96            class _Hash = hash<_Value>,
97            class _Pred = std::equal_to<_Value>,
98            class _Alloc = std::allocator<_Value>,
99            bool __cache_hash_code = false>
100     class __unordered_multiset
101     : public _Hashtable<_Value, _Value, _Alloc,
102                         std::_Identity<_Value>, _Pred,
103                         _Hash, __detail::_Mod_range_hashing,
104                         __detail::_Default_ranged_hash,
105                         __detail::_Prime_rehash_policy,
106                         __cache_hash_code, true, false>
107     {
108       typedef _Hashtable<_Value, _Value, _Alloc,
109                          std::_Identity<_Value>, _Pred,
110                          _Hash, __detail::_Mod_range_hashing,
111                          __detail::_Default_ranged_hash,
112                          __detail::_Prime_rehash_policy,
113                          __cache_hash_code, true, false>
114         _Base;
116     public:
117       typedef typename _Base::size_type       size_type;
118       typedef typename _Base::hasher          hasher;
119       typedef typename _Base::key_equal       key_equal;
120       typedef typename _Base::allocator_type  allocator_type;
121       
122       explicit
123       __unordered_multiset(size_type __n = 10,
124                            const hasher& __hf = hasher(),
125                            const key_equal& __eql = key_equal(),
126                            const allocator_type& __a = allocator_type())
127       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
128               __detail::_Default_ranged_hash(), __eql,
129               std::_Identity<_Value>(), __a)
130       { }
133       template<typename _InputIterator>
134         __unordered_multiset(_InputIterator __f, _InputIterator __l, 
135                              typename _Base::size_type __n = 0,
136                              const hasher& __hf = hasher(), 
137                              const key_equal& __eql = key_equal(), 
138                              const allocator_type& __a = allocator_type())
139         : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
140                 __detail::_Default_ranged_hash(), __eql,
141                 std::_Identity<_Value>(), __a)
142         { }
144 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
145       __unordered_multiset(__unordered_multiset&& __x)
146       : _Base(std::forward<_Base>(__x)) { }
147 #endif
148     };
150   template<class _Value, class _Hash, class _Pred, class _Alloc,
151            bool __cache_hash_code>
152     inline void
153     swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
154          __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
155     { __x.swap(__y); }
157   template<class _Value, class _Hash, class _Pred, class _Alloc,
158            bool __cache_hash_code>
159     inline void
160     swap(__unordered_multiset<_Value, _Hash, _Pred,
161          _Alloc, __cache_hash_code>& __x,
162          __unordered_multiset<_Value, _Hash, _Pred,
163          _Alloc, __cache_hash_code>& __y)
164     { __x.swap(__y); }
167   /**
168    *  @brief A standard container composed of unique keys (containing
169    *  at most one of each key value) in which the elements' keys are
170    *  the elements themselves.
171    *
172    *  @ingroup unordered_associative_containers
173    *
174    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
175    *  <a href="tables.html#xx">unordered associative container</a>
176    *
177    *  @param  Value  Type of key objects.
178    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
179    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
180    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
181    */
182   template<class _Value,
183            class _Hash = hash<_Value>,
184            class _Pred = std::equal_to<_Value>,
185            class _Alloc = std::allocator<_Value> >
186     class unordered_set
187     : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
188     {
189       typedef __unordered_set<_Value, _Hash, _Pred, _Alloc>  _Base;
191     public:
192       typedef typename _Base::value_type      value_type;
193       typedef typename _Base::size_type       size_type;
194       typedef typename _Base::hasher          hasher;
195       typedef typename _Base::key_equal       key_equal;
196       typedef typename _Base::allocator_type  allocator_type;
197       
198       explicit
199       unordered_set(size_type __n = 10,
200                     const hasher& __hf = hasher(),
201                     const key_equal& __eql = key_equal(),
202                     const allocator_type& __a = allocator_type())
203       : _Base(__n, __hf, __eql, __a)
204       { }
206       template<typename _InputIterator>
207         unordered_set(_InputIterator __f, _InputIterator __l, 
208                       size_type __n = 10,
209                       const hasher& __hf = hasher(), 
210                       const key_equal& __eql = key_equal(), 
211                       const allocator_type& __a = allocator_type())
212         : _Base(__f, __l, __n, __hf, __eql, __a)
213         { }
215 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
216       unordered_set(unordered_set&& __x)
217       : _Base(std::forward<_Base>(__x)) { }
219       unordered_set(initializer_list<value_type> __l,
220                     size_type __n = 10,
221                     const hasher& __hf = hasher(),
222                     const key_equal& __eql = key_equal(),
223                     const allocator_type& __a = allocator_type())
224         : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
225       { }
227       unordered_set&
228       operator=(unordered_set&& __x)
229       {
230         // NB: DR 675.
231         this->clear();
232         this->swap(__x); 
233         return *this;   
234       }
236       unordered_set&
237       operator=(initializer_list<value_type> __l)
238       {
239         this->clear();
240         this->insert(__l.begin(), __l.end());
241         return *this;
242       }
243 #endif
244     };
246   /**
247    *  @brief A standard container composed of equivalent keys
248    *  (possibly containing multiple of each key value) in which the
249    *  elements' keys are the elements themselves.
250    *
251    *  @ingroup unordered_associative_containers
252    *
253    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
254    *  <a href="tables.html#xx">unordered associative container</a>
255    *
256    *  @param  Value  Type of key objects.
257    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
258    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
259    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
260    */
261   template<class _Value,
262            class _Hash = hash<_Value>,
263            class _Pred = std::equal_to<_Value>,
264            class _Alloc = std::allocator<_Value> >
265     class unordered_multiset
266     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
267     {
268       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
270     public:
271       typedef typename _Base::value_type      value_type;
272       typedef typename _Base::size_type       size_type;
273       typedef typename _Base::hasher          hasher;
274       typedef typename _Base::key_equal       key_equal;
275       typedef typename _Base::allocator_type  allocator_type;
276       
277       explicit
278       unordered_multiset(size_type __n = 10,
279                          const hasher& __hf = hasher(),
280                          const key_equal& __eql = key_equal(),
281                          const allocator_type& __a = allocator_type())
282       : _Base(__n, __hf, __eql, __a)
283       { }
286       template<typename _InputIterator>
287         unordered_multiset(_InputIterator __f, _InputIterator __l, 
288                            typename _Base::size_type __n = 0,
289                            const hasher& __hf = hasher(), 
290                            const key_equal& __eql = key_equal(), 
291                            const allocator_type& __a = allocator_type())
292         : _Base(__f, __l, __n, __hf, __eql, __a)
293         { }
295 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
296       unordered_multiset(unordered_multiset&& __x)
297       : _Base(std::forward<_Base>(__x)) { }
299       unordered_multiset(initializer_list<value_type> __l,
300                          size_type __n = 10,
301                          const hasher& __hf = hasher(),
302                          const key_equal& __eql = key_equal(),
303                          const allocator_type& __a = allocator_type())
304         : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
305       { }
307       unordered_multiset&
308       operator=(unordered_multiset&& __x)
309       {
310         // NB: DR 675.
311         this->clear();
312         this->swap(__x); 
313         return *this;   
314       }
316       unordered_multiset&
317       operator=(initializer_list<value_type> __l)
318       {
319         this->clear();
320         this->insert(__l.begin(), __l.end());
321         return *this;
322       }
323 #endif
324     };
326   template<class _Value, class _Hash, class _Pred, class _Alloc>
327     inline void
328     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
329          unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
330     { __x.swap(__y); }
332   template<class _Value, class _Hash, class _Pred, class _Alloc>
333     inline void
334     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
335          unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
336     { __x.swap(__y); }
338 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
339   template<class _Value, class _Hash, class _Pred, class _Alloc>
340     inline void
341     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
342          unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
343     { __x.swap(__y); }
345   template<class _Value, class _Hash, class _Pred, class _Alloc>
346     inline void
347     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
348          unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
349     { __x.swap(__y); }
351   template<class _Value, class _Hash, class _Pred, class _Alloc>
352     inline void
353     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
354          unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
355     { __x.swap(__y); }
357   template<class _Value, class _Hash, class _Pred, class _Alloc>
358     inline void
359     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
360          unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
361     { __x.swap(__y); }
362 #endif
364 _GLIBCXX_END_NAMESPACE_TR1