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