]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/debug/multiset.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / debug / multiset.h
1 // Debugging 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/multiset.h
32  *  This file is a GNU debug extension to the Standard C++ Library.
33  */
34
35 #ifndef _GLIBCXX_DEBUG_MULTISET_H
36 #define _GLIBCXX_DEBUG_MULTISET_H 1
37
38 #include <debug/safe_sequence.h>
39 #include <debug/safe_iterator.h>
40 #include <utility>
41
42 namespace std
43 {
44 namespace __debug
45 {
46   template<typename _Key, typename _Compare = std::less<_Key>,
47            typename _Allocator = std::allocator<_Key> >
48     class multiset
49     : public _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator>,
50       public __gnu_debug::_Safe_sequence<multiset<_Key, _Compare, _Allocator> >
51     {
52       typedef _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> _Base;
53       typedef __gnu_debug::_Safe_sequence<multiset> _Safe_base;
54
55     public:
56       // types:
57       typedef _Key                                   key_type;
58       typedef _Key                                   value_type;
59       typedef _Compare                               key_compare;
60       typedef _Compare                               value_compare;
61       typedef _Allocator                             allocator_type;
62       typedef typename _Base::reference              reference;
63       typedef typename _Base::const_reference        const_reference;
64
65       typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, multiset>
66       iterator;
67       typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
68                                           multiset> const_iterator;
69
70       typedef typename _Base::size_type              size_type;
71       typedef typename _Base::difference_type        difference_type;
72       typedef typename _Base::pointer                pointer;
73       typedef typename _Base::const_pointer          const_pointer;
74       typedef std::reverse_iterator<iterator>        reverse_iterator;
75       typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
76
77       // 23.3.3.1 construct/copy/destroy:
78       explicit multiset(const _Compare& __comp = _Compare(),
79                         const _Allocator& __a = _Allocator())
80       : _Base(__comp, __a) { }
81
82       template<typename _InputIterator>
83         multiset(_InputIterator __first, _InputIterator __last,
84                  const _Compare& __comp = _Compare(),
85                  const _Allocator& __a = _Allocator())
86         : _Base(__gnu_debug::__check_valid_range(__first, __last), __last,
87                 __comp, __a) { }
88
89       multiset(const multiset& __x)
90       : _Base(__x), _Safe_base() { }
91
92       multiset(const _Base& __x)
93       : _Base(__x), _Safe_base() { }
94
95 #ifdef __GXX_EXPERIMENTAL_CXX0X__
96       multiset(multiset&& __x)
97       : _Base(std::forward<multiset>(__x)), _Safe_base()
98       { this->_M_swap(__x); }
99 #endif
100
101       ~multiset() { }
102
103       multiset&
104       operator=(const multiset& __x)
105       {
106         *static_cast<_Base*>(this) = __x;
107         this->_M_invalidate_all();
108         return *this;
109       }
110
111 #ifdef __GXX_EXPERIMENTAL_CXX0X__
112       multiset&
113       operator=(multiset&& __x)
114       {
115         // NB: DR 675.
116         clear();
117         swap(__x);
118         return *this;
119       }
120 #endif
121
122       using _Base::get_allocator;
123
124       // iterators:
125       iterator
126       begin()
127       { return iterator(_Base::begin(), this); }
128
129       const_iterator
130       begin() const
131       { return const_iterator(_Base::begin(), this); }
132
133       iterator
134       end()
135       { return iterator(_Base::end(), this); }
136
137       const_iterator
138       end() const
139       { return const_iterator(_Base::end(), this); }
140
141       reverse_iterator
142       rbegin()
143       { return reverse_iterator(end()); }
144
145       const_reverse_iterator
146       rbegin() const
147       { return const_reverse_iterator(end()); }
148
149       reverse_iterator
150       rend()
151       { return reverse_iterator(begin()); }
152
153       const_reverse_iterator
154       rend() const
155       { return const_reverse_iterator(begin()); }
156
157 #ifdef __GXX_EXPERIMENTAL_CXX0X__
158       const_iterator
159       cbegin() const
160       { return const_iterator(_Base::begin(), this); }
161
162       const_iterator
163       cend() const
164       { return const_iterator(_Base::end(), this); }
165
166       const_reverse_iterator
167       crbegin() const
168       { return const_reverse_iterator(end()); }
169
170       const_reverse_iterator
171       crend() const
172       { return const_reverse_iterator(begin()); }
173 #endif
174
175       // capacity:
176       using _Base::empty;
177       using _Base::size;
178       using _Base::max_size;
179
180       // modifiers:
181       iterator
182       insert(const value_type& __x)
183       { return iterator(_Base::insert(__x), this); }
184
185       iterator
186       insert(iterator __position, const value_type& __x)
187       {
188         __glibcxx_check_insert(__position);
189         return iterator(_Base::insert(__position.base(), __x), this);
190       }
191
192       template<typename _InputIterator>
193       void
194       insert(_InputIterator __first, _InputIterator __last)
195       {
196         __glibcxx_check_valid_range(__first, __last);
197         _Base::insert(__first, __last);
198       }
199
200       void
201       erase(iterator __position)
202       {
203         __glibcxx_check_erase(__position);
204         __position._M_invalidate();
205         _Base::erase(__position.base());
206       }
207
208       size_type
209       erase(const key_type& __x)
210       {
211         std::pair<iterator, iterator> __victims = this->equal_range(__x);
212         size_type __count = 0;
213         while (__victims.first != __victims.second)
214         {
215           iterator __victim = __victims.first++;
216           __victim._M_invalidate();
217           _Base::erase(__victim.base());
218           ++__count;
219         }
220         return __count;
221       }
222
223       void
224       erase(iterator __first, iterator __last)
225       {
226         // _GLIBCXX_RESOLVE_LIB_DEFECTS
227         // 151. can't currently clear() empty container
228         __glibcxx_check_erase_range(__first, __last);
229         while (__first != __last)
230         this->erase(__first++);
231       }
232
233       void
234 #ifdef __GXX_EXPERIMENTAL_CXX0X__
235       swap(multiset&& __x)
236 #else
237       swap(multiset& __x)
238 #endif
239       {
240         _Base::swap(__x);
241         this->_M_swap(__x);
242       }
243
244       void
245       clear()
246       { this->erase(begin(), end()); }
247
248       // observers:
249       using _Base::key_comp;
250       using _Base::value_comp;
251
252       // multiset operations:
253       iterator
254       find(const key_type& __x)
255       { return iterator(_Base::find(__x), this); }
256
257       // _GLIBCXX_RESOLVE_LIB_DEFECTS
258       // 214. set::find() missing const overload
259       const_iterator
260       find(const key_type& __x) const
261       { return const_iterator(_Base::find(__x), this); }
262
263       using _Base::count;
264
265       iterator
266       lower_bound(const key_type& __x)
267       { return iterator(_Base::lower_bound(__x), this); }
268
269       // _GLIBCXX_RESOLVE_LIB_DEFECTS
270       // 214. set::find() missing const overload
271       const_iterator
272       lower_bound(const key_type& __x) const
273       { return const_iterator(_Base::lower_bound(__x), this); }
274
275       iterator
276       upper_bound(const key_type& __x)
277       { return iterator(_Base::upper_bound(__x), this); }
278
279       // _GLIBCXX_RESOLVE_LIB_DEFECTS
280       // 214. set::find() missing const overload
281       const_iterator
282       upper_bound(const key_type& __x) const
283       { return const_iterator(_Base::upper_bound(__x), this); }
284
285       std::pair<iterator,iterator>
286       equal_range(const key_type& __x)
287       {
288         typedef typename _Base::iterator _Base_iterator;
289         std::pair<_Base_iterator, _Base_iterator> __res =
290         _Base::equal_range(__x);
291         return std::make_pair(iterator(__res.first, this),
292                               iterator(__res.second, this));
293       }
294
295       // _GLIBCXX_RESOLVE_LIB_DEFECTS
296       // 214. set::find() missing const overload
297       std::pair<const_iterator,const_iterator>
298       equal_range(const key_type& __x) const
299       {
300         typedef typename _Base::const_iterator _Base_iterator;
301         std::pair<_Base_iterator, _Base_iterator> __res =
302         _Base::equal_range(__x);
303         return std::make_pair(const_iterator(__res.first, this),
304                               const_iterator(__res.second, this));
305       }
306
307       _Base&
308       _M_base() { return *this; }
309
310       const _Base&
311       _M_base() const { return *this; }
312
313     private:
314       void
315       _M_invalidate_all()
316       {
317         typedef typename _Base::const_iterator _Base_const_iterator;
318         typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
319         this->_M_invalidate_if(_Not_equal(_M_base().end()));
320       }
321     };
322
323   template<typename _Key, typename _Compare, typename _Allocator>
324     inline bool
325     operator==(const multiset<_Key, _Compare, _Allocator>& __lhs,
326                const multiset<_Key, _Compare, _Allocator>& __rhs)
327     { return __lhs._M_base() == __rhs._M_base(); }
328
329   template<typename _Key, typename _Compare, typename _Allocator>
330     inline bool
331     operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs,
332                const multiset<_Key, _Compare, _Allocator>& __rhs)
333     { return __lhs._M_base() != __rhs._M_base(); }
334
335   template<typename _Key, typename _Compare, typename _Allocator>
336     inline bool
337     operator<(const multiset<_Key, _Compare, _Allocator>& __lhs,
338               const multiset<_Key, _Compare, _Allocator>& __rhs)
339     { return __lhs._M_base() < __rhs._M_base(); }
340
341   template<typename _Key, typename _Compare, typename _Allocator>
342     inline bool
343     operator<=(const multiset<_Key, _Compare, _Allocator>& __lhs,
344                const multiset<_Key, _Compare, _Allocator>& __rhs)
345     { return __lhs._M_base() <= __rhs._M_base(); }
346
347   template<typename _Key, typename _Compare, typename _Allocator>
348     inline bool
349     operator>=(const multiset<_Key, _Compare, _Allocator>& __lhs,
350                const multiset<_Key, _Compare, _Allocator>& __rhs)
351     { return __lhs._M_base() >= __rhs._M_base(); }
352
353   template<typename _Key, typename _Compare, typename _Allocator>
354     inline bool
355     operator>(const multiset<_Key, _Compare, _Allocator>& __lhs,
356               const multiset<_Key, _Compare, _Allocator>& __rhs)
357     { return __lhs._M_base() > __rhs._M_base(); }
358
359   template<typename _Key, typename _Compare, typename _Allocator>
360     void
361     swap(multiset<_Key, _Compare, _Allocator>& __x,
362          multiset<_Key, _Compare, _Allocator>& __y)
363     { return __x.swap(__y); }
364
365 #ifdef __GXX_EXPERIMENTAL_CXX0X__
366   template<typename _Key, typename _Compare, typename _Allocator>
367     void
368     swap(multiset<_Key, _Compare, _Allocator>&& __x,
369          multiset<_Key, _Compare, _Allocator>& __y)
370     { return __x.swap(__y); }
371
372   template<typename _Key, typename _Compare, typename _Allocator>
373     void
374     swap(multiset<_Key, _Compare, _Allocator>& __x,
375          multiset<_Key, _Compare, _Allocator>&& __y)
376     { return __x.swap(__y); }
377 #endif
378
379 } // namespace __debug
380 } // namespace std
381
382 #endif