]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/debug/unordered_set
Inital import
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / debug / unordered_set
1 // Debugging unordered_set/unordered_multiset implementation -*- C++ -*-
2
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.
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_set
32  *  This file is a GNU debug extension to the Standard C++ Library.
33  */
34
35 #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
36 #define _GLIBCXX_DEBUG_UNORDERED_SET 1
37
38 #ifdef __GXX_EXPERIMENTAL_CXX0X__
39 # include <unordered_set>
40 #else
41 # include <c++0x_warning.h>
42 #endif
43
44 #include <debug/safe_association.h>
45 #include <debug/safe_iterator.h>
46
47 #define _GLIBCXX_BASE unordered_set<_Value, _Hash, _Pred, _Alloc>
48 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
49
50 namespace std
51 {
52 namespace __debug
53 {
54   template<typename _Value,
55            typename _Hash  = std::hash<_Value>,
56            typename _Pred = std::equal_to<_Value>,
57            typename _Alloc =  std::allocator<_Value> >
58     class unordered_set
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_set> _Safe_base;
65
66     public:
67       typedef typename _Safe_assoc::size_type       size_type;
68       typedef typename _Safe_assoc::hasher          hasher;
69       typedef typename _Safe_assoc::key_equal       key_equal;
70       typedef typename _Safe_assoc::allocator_type allocator_type;
71
72       explicit
73       unordered_set(size_type __n = 10,
74                     const hasher& __hf = hasher(),
75                     const key_equal& __eql = key_equal(),
76                     const allocator_type& __a = allocator_type())
77       : _Safe_assoc(__n, __hf, __eql, __a)
78       { }
79
80       template<typename _InputIterator>
81         unordered_set(_InputIterator __f, _InputIterator __l, 
82                       size_type __n = 10,
83                       const hasher& __hf = hasher(), 
84                       const key_equal& __eql = key_equal(), 
85                       const allocator_type& __a = allocator_type())
86         : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
87         { }
88
89       unordered_set(const _Safe_assoc& __x) 
90       : _Safe_assoc(__x), _Safe_base() { }
91
92       unordered_set(unordered_set&& __x) 
93       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
94
95       unordered_set&
96       operator=(unordered_set&& __x)
97       {
98         // NB: DR 675.
99         clear();
100         swap(__x);
101         return *this;
102       }
103
104       void
105       swap(unordered_set&& __x)
106       {
107         _Safe_assoc::swap(__x);
108         _Safe_base::_M_swap(__x);
109       }
110
111       void
112       clear()
113       {
114         _Base::clear();
115         this->_M_invalidate_all();
116       }
117
118     private:
119       void
120       _M_invalidate_all()
121       {
122         typedef typename _Base::const_iterator _Base_const_iterator;
123         typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
124         this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
125       }
126     };
127
128   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
129     inline void
130     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
131          unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
132     { __x.swap(__y); }
133
134   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
135     inline void
136     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
137          unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
138     { __x.swap(__y); }
139
140   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
141     inline void
142     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
143          unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
144     { __x.swap(__y); }
145
146 #undef _GLIBCXX_BASE
147 #undef _GLIBCXX_STD_BASE
148 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
149 #define _GLIBCXX_BASE unordered_multiset<_Value, _Hash, _Pred, _Alloc>
150
151   template<typename _Value,
152            typename _Hash  = std::hash<_Value>,
153            typename _Pred = std::equal_to<_Value>,
154            typename _Alloc =  std::allocator<_Value> >
155     class unordered_multiset
156     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
157       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
158     {
159       typedef typename _GLIBCXX_STD_BASE _Base;
160       typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
161       typedef __gnu_debug::_Safe_sequence<unordered_multiset> _Safe_base;
162
163     public:
164       typedef typename _Safe_assoc::size_type       size_type;
165       typedef typename _Safe_assoc::hasher          hasher;
166       typedef typename _Safe_assoc::key_equal       key_equal;
167       typedef typename _Safe_assoc::allocator_type allocator_type;
168
169       explicit
170       unordered_multiset(size_type __n = 10,
171                     const hasher& __hf = hasher(),
172                     const key_equal& __eql = key_equal(),
173                     const allocator_type& __a = allocator_type())
174       : _Safe_assoc(__n, __hf, __eql, __a)
175       { }
176
177       template<typename _InputIterator>
178         unordered_multiset(_InputIterator __f, _InputIterator __l, 
179                       size_type __n = 10,
180                       const hasher& __hf = hasher(), 
181                       const key_equal& __eql = key_equal(), 
182                       const allocator_type& __a = allocator_type())
183         : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
184         { }
185
186       unordered_multiset(const _Safe_assoc& __x) 
187       : _Safe_assoc(__x), _Safe_base() { }
188
189       unordered_multiset(unordered_multiset&& __x) 
190       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
191
192       unordered_multiset&
193       operator=(unordered_multiset&& __x)
194       {
195         // NB: DR 675.
196         clear();
197         swap(__x);
198         return *this;
199       }
200
201       void
202       swap(unordered_multiset&& __x)
203       {
204         _Safe_assoc::swap(__x);
205         _Safe_base::_M_swap(__x);
206       }
207
208      void
209       clear()
210       {
211         _Base::clear();
212         this->_M_invalidate_all();
213       }
214
215     private:
216       void
217       _M_invalidate_all()
218       {
219         typedef typename _Base::const_iterator _Base_const_iterator;
220         typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
221         this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
222       }
223     };
224
225   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
226     inline void
227     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
228          unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
229     { __x.swap(__y); }
230
231   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
232     inline void
233     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
234          unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
235     { __x.swap(__y); }
236
237   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
238     inline void
239     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
240          unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
241     { __x.swap(__y); }
242
243 } // namespace __debug
244 } // namespace std
245
246 #undef _GLIBCXX_BASE
247 #undef _GLIBCXX_STD_BASE
248
249 #endif