OSDN Git Service

merge branch profile-stdlib
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / profile / multimap.h
1 // Profiling multimap implementation -*- C++ -*-
2
3 // Copyright (C) 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /** @file profile/multimap.h
26  *  This file is a GNU profile extension to the Standard C++ Library.
27  */
28
29 #ifndef _GLIBCXX_PROFILE_MULTIMAP_H
30 #define _GLIBCXX_PROFILE_MULTIMAP_H 1
31
32 #include <utility>
33
34 namespace std
35 {
36 namespace __profile
37 {
38   /** @brief Multimap wrapper with performance instrumentation.  */
39   template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
40            typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
41     class multimap
42     : public _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator>
43     {
44       typedef _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
45
46     public:
47       // types:
48       typedef _Key                                   key_type;
49       typedef _Tp                                    mapped_type;
50       typedef std::pair<const _Key, _Tp>             value_type;
51       typedef _Compare                               key_compare;
52       typedef _Allocator                             allocator_type;
53       typedef typename _Base::reference              reference;
54       typedef typename _Base::const_reference        const_reference;
55
56       typedef typename _Base::iterator               iterator;
57       typedef typename _Base::const_iterator         const_iterator;
58       typedef typename _Base::reverse_iterator       reverse_iterator;
59       typedef typename _Base::const_reverse_iterator const_reverse_iterator;
60
61       typedef typename _Base::size_type              size_type;
62       typedef typename _Base::difference_type        difference_type;
63       typedef typename _Base::pointer                pointer;
64       typedef typename _Base::const_pointer          const_pointer;
65
66       using _Base::value_compare;
67
68       // 23.3.1.1 construct/copy/destroy:
69       explicit multimap(const _Compare& __comp = _Compare(),
70                         const _Allocator& __a = _Allocator())
71       : _Base(__comp, __a) { }
72
73       template<typename _InputIterator>
74       multimap(_InputIterator __first, _InputIterator __last,
75                const _Compare& __comp = _Compare(),
76                const _Allocator& __a = _Allocator())
77       : _Base(__first, __last, __comp, __a) { }
78
79       multimap(const multimap& __x)
80       : _Base(__x) { }
81
82       multimap(const _Base& __x)
83       : _Base(__x) { }
84
85 #ifdef __GXX_EXPERIMENTAL_CXX0X__
86       multimap(multimap&& __x)
87       : _Base(std::forward<multimap>(__x))
88       { }
89
90       multimap(initializer_list<value_type> __l,
91                const _Compare& __c = _Compare(),
92                const allocator_type& __a = allocator_type())
93       : _Base(__l, __c, __a) { }
94 #endif
95
96       ~multimap() { }
97
98       multimap&
99       operator=(const multimap& __x)
100       {
101         *static_cast<_Base*>(this) = __x;
102         return *this;
103       }
104
105 #ifdef __GXX_EXPERIMENTAL_CXX0X__
106       multimap&
107       operator=(multimap&& __x)
108       {
109         // NB: DR 675.
110         this->clear();
111         this->swap(__x);
112         return *this;
113       }
114
115       multimap&
116       operator=(initializer_list<value_type> __l)
117       {
118         this->clear();
119         this->insert(__l);
120         return *this;
121       }
122 #endif
123
124       using _Base::get_allocator;
125
126       // iterators:
127       iterator
128       begin()
129       { return iterator(_Base::begin()); }
130
131       const_iterator
132       begin() const
133       { return const_iterator(_Base::begin()); }
134
135       iterator
136       end()
137       { return iterator(_Base::end()); }
138
139       const_iterator
140       end() const
141       { return const_iterator(_Base::end()); }
142
143       reverse_iterator
144       rbegin()
145       { return reverse_iterator(end()); }
146
147       const_reverse_iterator
148       rbegin() const
149       { return const_reverse_iterator(end()); }
150
151       reverse_iterator
152       rend()
153       { return reverse_iterator(begin()); }
154
155       const_reverse_iterator
156       rend() const
157       { return const_reverse_iterator(begin()); }
158
159 #ifdef __GXX_EXPERIMENTAL_CXX0X__
160       const_iterator
161       cbegin() const
162       { return const_iterator(_Base::begin()); }
163
164       const_iterator
165       cend() const
166       { return const_iterator(_Base::end()); }
167
168       const_reverse_iterator
169       crbegin() const
170       { return const_reverse_iterator(end()); }
171
172       const_reverse_iterator
173       crend() const
174       { return const_reverse_iterator(begin()); }
175 #endif
176
177       // capacity:
178       using _Base::empty;
179       using _Base::size;
180       using _Base::max_size;
181
182       // modifiers:
183       iterator
184       insert(const value_type& __x)
185       { return iterator(_Base::insert(__x)); }
186
187 #ifdef __GXX_EXPERIMENTAL_CXX0X__
188       void
189       insert(std::initializer_list<value_type> __list)
190       { _Base::insert(__list); }
191 #endif
192
193       iterator
194       insert(iterator __position, const value_type& __x)
195       {
196         return iterator(_Base::insert(__position, __x));
197       }
198
199       template<typename _InputIterator>
200         void
201         insert(_InputIterator __first, _InputIterator __last)
202         {
203           _Base::insert(__first, __last);
204         }
205
206 #ifdef __GXX_EXPERIMENTAL_CXX0X__
207       iterator
208       erase(iterator __position)
209       {
210         return _Base::erase(__position);
211       }
212 #else
213       void
214       erase(iterator __position)
215       {
216         _Base::erase(__position);
217       }
218 #endif
219
220       size_type
221       erase(const key_type& __x)
222       {
223         std::pair<iterator, iterator> __victims = this->equal_range(__x);
224         size_type __count = 0;
225         while (__victims.first != __victims.second)
226         {
227           iterator __victim = __victims.first++;
228           _Base::erase(__victim);
229           ++__count;
230         }
231         return __count;
232       }
233
234       void
235       erase(iterator __first, iterator __last)
236       {
237         // _GLIBCXX_RESOLVE_LIB_DEFECTS
238         // 151. can't currently clear() empty container
239         while (__first != __last)
240         this->erase(__first++);
241       }
242
243       void
244       swap(multimap& __x)
245       {
246         _Base::swap(__x);
247       }
248
249       void
250       clear()
251       { this->erase(begin(), end()); }
252
253       // observers:
254       using _Base::key_comp;
255       using _Base::value_comp;
256
257       // 23.3.1.3 multimap operations:
258       iterator
259       find(const key_type& __x)
260       { return iterator(_Base::find(__x)); }
261
262       const_iterator
263       find(const key_type& __x) const
264       { return const_iterator(_Base::find(__x)); }
265
266       using _Base::count;
267
268       iterator
269       lower_bound(const key_type& __x)
270       { return iterator(_Base::lower_bound(__x)); }
271
272       const_iterator
273       lower_bound(const key_type& __x) const
274       { return const_iterator(_Base::lower_bound(__x)); }
275
276       iterator
277       upper_bound(const key_type& __x)
278       { return iterator(_Base::upper_bound(__x)); }
279
280       const_iterator
281       upper_bound(const key_type& __x) const
282       { return const_iterator(_Base::upper_bound(__x)); }
283
284       std::pair<iterator,iterator>
285       equal_range(const key_type& __x)
286       {
287         typedef typename _Base::iterator _Base_iterator;
288         std::pair<_Base_iterator, _Base_iterator> __res =
289         _Base::equal_range(__x);
290         return std::make_pair(iterator(__res.first),
291                               iterator(__res.second));
292       }
293
294       std::pair<const_iterator,const_iterator>
295       equal_range(const key_type& __x) const
296       {
297         typedef typename _Base::const_iterator _Base_const_iterator;
298         std::pair<_Base_const_iterator, _Base_const_iterator> __res =
299         _Base::equal_range(__x);
300         return std::make_pair(const_iterator(__res.first),
301                               const_iterator(__res.second));
302       }
303
304       _Base&
305       _M_base() { return *this; }
306
307       const _Base&
308       _M_base() const { return *this; }
309     };
310
311   template<typename _Key, typename _Tp,
312            typename _Compare, typename _Allocator>
313     inline bool
314     operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
315                const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
316     { return __lhs._M_base() == __rhs._M_base(); }
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 void
356     swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
357          multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
358     { __lhs.swap(__rhs); }
359
360 } // namespace __profile
361 } // namespace std
362
363 #endif