Merged with trunk at revision 155767
[official-gcc.git] / libstdc++-v3 / include / profile / multiset.h
blob653ba5b465336a27c4d787d6808d2bb4dca4e201
1 // Profiling multiset implementation -*- C++ -*-
3 // Copyright (C) 2009, 2010 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.
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 // 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.
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/>.
25 /** @file profile/multiset.h
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_MULTISET_H
30 #define _GLIBCXX_PROFILE_MULTISET_H 1
32 #include <utility>
34 namespace std
36 namespace __profile
38 /// Class std::multiset wrapper with performance instrumentation.
39 template<typename _Key, typename _Compare = std::less<_Key>,
40 typename _Allocator = std::allocator<_Key> >
41 class multiset
42 : public _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator>
44 typedef _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> _Base;
46 public:
47 // types:
48 typedef _Key key_type;
49 typedef _Key value_type;
50 typedef _Compare key_compare;
51 typedef _Compare value_compare;
52 typedef _Allocator allocator_type;
53 typedef typename _Base::reference reference;
54 typedef typename _Base::const_reference const_reference;
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;
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;
66 // 23.3.3.1 construct/copy/destroy:
67 explicit multiset(const _Compare& __comp = _Compare(),
68 const _Allocator& __a = _Allocator())
69 : _Base(__comp, __a) { }
71 template<typename _InputIterator>
72 multiset(_InputIterator __first, _InputIterator __last,
73 const _Compare& __comp = _Compare(),
74 const _Allocator& __a = _Allocator())
75 : _Base(__first, __last, __comp, __a) { }
77 multiset(const multiset& __x)
78 : _Base(__x) { }
80 multiset(const _Base& __x)
81 : _Base(__x) { }
83 #ifdef __GXX_EXPERIMENTAL_CXX0X__
84 multiset(multiset&& __x)
85 : _Base(std::forward<multiset>(__x))
86 { }
88 multiset(initializer_list<value_type> __l,
89 const _Compare& __comp = _Compare(),
90 const allocator_type& __a = allocator_type())
91 : _Base(__l, __comp, __a) { }
92 #endif
94 ~multiset() { }
96 multiset&
97 operator=(const multiset& __x)
99 *static_cast<_Base*>(this) = __x;
100 return *this;
103 #ifdef __GXX_EXPERIMENTAL_CXX0X__
104 multiset&
105 operator=(multiset&& __x)
107 // NB: DR 1204.
108 // NB: DR 675.
109 this->clear();
110 this->swap(__x);
111 return *this;
114 multiset&
115 operator=(initializer_list<value_type> __l)
117 this->clear();
118 this->insert(__l);
119 return *this;
121 #endif
123 using _Base::get_allocator;
125 // iterators:
126 iterator
127 begin()
128 { return iterator(_Base::begin()); }
130 const_iterator
131 begin() const
132 { return const_iterator(_Base::begin()); }
134 iterator
135 end()
136 { return iterator(_Base::end()); }
138 const_iterator
139 end() const
140 { return const_iterator(_Base::end()); }
142 reverse_iterator
143 rbegin()
144 { return reverse_iterator(end()); }
146 const_reverse_iterator
147 rbegin() const
148 { return const_reverse_iterator(end()); }
150 reverse_iterator
151 rend()
152 { return reverse_iterator(begin()); }
154 const_reverse_iterator
155 rend() const
156 { return const_reverse_iterator(begin()); }
158 #ifdef __GXX_EXPERIMENTAL_CXX0X__
159 const_iterator
160 cbegin() const
161 { return const_iterator(_Base::begin()); }
163 const_iterator
164 cend() const
165 { return const_iterator(_Base::end()); }
167 const_reverse_iterator
168 crbegin() const
169 { return const_reverse_iterator(end()); }
171 const_reverse_iterator
172 crend() const
173 { return const_reverse_iterator(begin()); }
174 #endif
176 // capacity:
177 using _Base::empty;
178 using _Base::size;
179 using _Base::max_size;
181 // modifiers:
182 iterator
183 insert(const value_type& __x)
184 { return iterator(_Base::insert(__x)); }
186 iterator
187 insert(iterator __position, const value_type& __x)
189 return iterator(_Base::insert(__position, __x));
192 template<typename _InputIterator>
193 void
194 insert(_InputIterator __first, _InputIterator __last)
196 _Base::insert(__first, __last);
199 #ifdef __GXX_EXPERIMENTAL_CXX0X__
200 void
201 insert(initializer_list<value_type> __l)
202 { _Base::insert(__l); }
203 #endif
205 #ifdef __GXX_EXPERIMENTAL_CXX0X__
206 iterator
207 erase(iterator __position)
208 { return _Base::erase(__position); }
209 #else
210 void
211 erase(iterator __position)
212 { _Base::erase(__position); }
213 #endif
215 size_type
216 erase(const key_type& __x)
218 std::pair<iterator, iterator> __victims = this->equal_range(__x);
219 size_type __count = 0;
220 while (__victims.first != __victims.second)
222 iterator __victim = __victims.first++;
223 _Base::erase(__victim);
224 ++__count;
226 return __count;
229 #ifdef __GXX_EXPERIMENTAL_CXX0X__
230 iterator
231 erase(iterator __first, iterator __last)
233 // _GLIBCXX_RESOLVE_LIB_DEFECTS
234 // 151. can't currently clear() empty container
235 while (__first != __last)
236 this->erase(__first++);
237 return __last;
239 #else
240 void
241 erase(iterator __first, iterator __last)
243 // _GLIBCXX_RESOLVE_LIB_DEFECTS
244 // 151. can't currently clear() empty container
245 while (__first != __last)
246 this->erase(__first++);
248 #endif
250 void
251 swap(multiset& __x)
253 _Base::swap(__x);
256 void
257 clear()
258 { this->erase(begin(), end()); }
260 // observers:
261 using _Base::key_comp;
262 using _Base::value_comp;
264 // multiset operations:
265 iterator
266 find(const key_type& __x)
267 { return iterator(_Base::find(__x)); }
269 // _GLIBCXX_RESOLVE_LIB_DEFECTS
270 // 214. set::find() missing const overload
271 const_iterator
272 find(const key_type& __x) const
273 { return const_iterator(_Base::find(__x)); }
275 using _Base::count;
277 iterator
278 lower_bound(const key_type& __x)
279 { return iterator(_Base::lower_bound(__x)); }
281 // _GLIBCXX_RESOLVE_LIB_DEFECTS
282 // 214. set::find() missing const overload
283 const_iterator
284 lower_bound(const key_type& __x) const
285 { return const_iterator(_Base::lower_bound(__x)); }
287 iterator
288 upper_bound(const key_type& __x)
289 { return iterator(_Base::upper_bound(__x)); }
291 // _GLIBCXX_RESOLVE_LIB_DEFECTS
292 // 214. set::find() missing const overload
293 const_iterator
294 upper_bound(const key_type& __x) const
295 { return const_iterator(_Base::upper_bound(__x)); }
297 std::pair<iterator,iterator>
298 equal_range(const key_type& __x)
300 typedef typename _Base::iterator _Base_iterator;
301 std::pair<_Base_iterator, _Base_iterator> __res =
302 _Base::equal_range(__x);
303 return std::make_pair(iterator(__res.first),
304 iterator(__res.second));
307 // _GLIBCXX_RESOLVE_LIB_DEFECTS
308 // 214. set::find() missing const overload
309 std::pair<const_iterator,const_iterator>
310 equal_range(const key_type& __x) const
312 typedef typename _Base::const_iterator _Base_iterator;
313 std::pair<_Base_iterator, _Base_iterator> __res =
314 _Base::equal_range(__x);
315 return std::make_pair(const_iterator(__res.first),
316 const_iterator(__res.second));
319 _Base&
320 _M_base() { return *this; }
322 const _Base&
323 _M_base() const { return *this; }
327 template<typename _Key, typename _Compare, typename _Allocator>
328 inline bool
329 operator==(const multiset<_Key, _Compare, _Allocator>& __lhs,
330 const multiset<_Key, _Compare, _Allocator>& __rhs)
331 { return __lhs._M_base() == __rhs._M_base(); }
333 template<typename _Key, typename _Compare, typename _Allocator>
334 inline bool
335 operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs,
336 const multiset<_Key, _Compare, _Allocator>& __rhs)
337 { return __lhs._M_base() != __rhs._M_base(); }
339 template<typename _Key, typename _Compare, typename _Allocator>
340 inline bool
341 operator<(const multiset<_Key, _Compare, _Allocator>& __lhs,
342 const multiset<_Key, _Compare, _Allocator>& __rhs)
343 { return __lhs._M_base() < __rhs._M_base(); }
345 template<typename _Key, typename _Compare, typename _Allocator>
346 inline bool
347 operator<=(const multiset<_Key, _Compare, _Allocator>& __lhs,
348 const multiset<_Key, _Compare, _Allocator>& __rhs)
349 { return __lhs._M_base() <= __rhs._M_base(); }
351 template<typename _Key, typename _Compare, typename _Allocator>
352 inline bool
353 operator>=(const multiset<_Key, _Compare, _Allocator>& __lhs,
354 const multiset<_Key, _Compare, _Allocator>& __rhs)
355 { return __lhs._M_base() >= __rhs._M_base(); }
357 template<typename _Key, typename _Compare, typename _Allocator>
358 inline bool
359 operator>(const multiset<_Key, _Compare, _Allocator>& __lhs,
360 const multiset<_Key, _Compare, _Allocator>& __rhs)
361 { return __lhs._M_base() > __rhs._M_base(); }
363 template<typename _Key, typename _Compare, typename _Allocator>
364 void
365 swap(multiset<_Key, _Compare, _Allocator>& __x,
366 multiset<_Key, _Compare, _Allocator>& __y)
367 { return __x.swap(__y); }
369 } // namespace __profile
370 } // namespace std
372 #endif