]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/profile/multimap.h
set.h: Protect move assignment operator vs self assignment.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / multimap.h
1 // Profiling multimap implementation -*- C++ -*-
2
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.
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 /// Class std::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 if (this != &__x)
110 {
111 // NB: DR 675.
112 this->clear();
113 this->swap(__x);
114 }
115 return *this;
116 }
117
118 multimap&
119 operator=(initializer_list<value_type> __l)
120 {
121 this->clear();
122 this->insert(__l);
123 return *this;
124 }
125 #endif
126
127 using _Base::get_allocator;
128
129 // iterators:
130 iterator
131 begin()
132 { return iterator(_Base::begin()); }
133
134 const_iterator
135 begin() const
136 { return const_iterator(_Base::begin()); }
137
138 iterator
139 end()
140 { return iterator(_Base::end()); }
141
142 const_iterator
143 end() const
144 { return const_iterator(_Base::end()); }
145
146 reverse_iterator
147 rbegin()
148 { return reverse_iterator(end()); }
149
150 const_reverse_iterator
151 rbegin() const
152 { return const_reverse_iterator(end()); }
153
154 reverse_iterator
155 rend()
156 { return reverse_iterator(begin()); }
157
158 const_reverse_iterator
159 rend() const
160 { return const_reverse_iterator(begin()); }
161
162 #ifdef __GXX_EXPERIMENTAL_CXX0X__
163 const_iterator
164 cbegin() const
165 { return const_iterator(_Base::begin()); }
166
167 const_iterator
168 cend() const
169 { return const_iterator(_Base::end()); }
170
171 const_reverse_iterator
172 crbegin() const
173 { return const_reverse_iterator(end()); }
174
175 const_reverse_iterator
176 crend() const
177 { return const_reverse_iterator(begin()); }
178 #endif
179
180 // capacity:
181 using _Base::empty;
182 using _Base::size;
183 using _Base::max_size;
184
185 // modifiers:
186 iterator
187 insert(const value_type& __x)
188 { return iterator(_Base::insert(__x)); }
189
190 #ifdef __GXX_EXPERIMENTAL_CXX0X__
191 void
192 insert(std::initializer_list<value_type> __list)
193 { _Base::insert(__list); }
194 #endif
195
196 iterator
197 insert(iterator __position, const value_type& __x)
198 {
199 return iterator(_Base::insert(__position, __x));
200 }
201
202 template<typename _InputIterator>
203 void
204 insert(_InputIterator __first, _InputIterator __last)
205 {
206 _Base::insert(__first, __last);
207 }
208
209 #ifdef __GXX_EXPERIMENTAL_CXX0X__
210 iterator
211 erase(iterator __position)
212 { return _Base::erase(__position); }
213 #else
214 void
215 erase(iterator __position)
216 { _Base::erase(__position); }
217 #endif
218
219 size_type
220 erase(const key_type& __x)
221 {
222 std::pair<iterator, iterator> __victims = this->equal_range(__x);
223 size_type __count = 0;
224 while (__victims.first != __victims.second)
225 {
226 iterator __victim = __victims.first++;
227 _Base::erase(__victim);
228 ++__count;
229 }
230 return __count;
231 }
232
233 #ifdef __GXX_EXPERIMENTAL_CXX0X__
234 iterator
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 return __last;
242 }
243 #else
244 void
245 erase(iterator __first, iterator __last)
246 {
247 // _GLIBCXX_RESOLVE_LIB_DEFECTS
248 // 151. can't currently clear() empty container
249 while (__first != __last)
250 this->erase(__first++);
251 }
252 #endif
253
254 void
255 swap(multimap& __x)
256 {
257 _Base::swap(__x);
258 }
259
260 void
261 clear()
262 { this->erase(begin(), end()); }
263
264 // observers:
265 using _Base::key_comp;
266 using _Base::value_comp;
267
268 // 23.3.1.3 multimap operations:
269 iterator
270 find(const key_type& __x)
271 { return iterator(_Base::find(__x)); }
272
273 const_iterator
274 find(const key_type& __x) const
275 { return const_iterator(_Base::find(__x)); }
276
277 using _Base::count;
278
279 iterator
280 lower_bound(const key_type& __x)
281 { return iterator(_Base::lower_bound(__x)); }
282
283 const_iterator
284 lower_bound(const key_type& __x) const
285 { return const_iterator(_Base::lower_bound(__x)); }
286
287 iterator
288 upper_bound(const key_type& __x)
289 { return iterator(_Base::upper_bound(__x)); }
290
291 const_iterator
292 upper_bound(const key_type& __x) const
293 { return const_iterator(_Base::upper_bound(__x)); }
294
295 std::pair<iterator,iterator>
296 equal_range(const key_type& __x)
297 {
298 typedef typename _Base::iterator _Base_iterator;
299 std::pair<_Base_iterator, _Base_iterator> __res =
300 _Base::equal_range(__x);
301 return std::make_pair(iterator(__res.first),
302 iterator(__res.second));
303 }
304
305 std::pair<const_iterator,const_iterator>
306 equal_range(const key_type& __x) const
307 {
308 typedef typename _Base::const_iterator _Base_const_iterator;
309 std::pair<_Base_const_iterator, _Base_const_iterator> __res =
310 _Base::equal_range(__x);
311 return std::make_pair(const_iterator(__res.first),
312 const_iterator(__res.second));
313 }
314
315 _Base&
316 _M_base() { return *this; }
317
318 const _Base&
319 _M_base() const { return *this; }
320 };
321
322 template<typename _Key, typename _Tp,
323 typename _Compare, typename _Allocator>
324 inline bool
325 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
326 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
327 { return __lhs._M_base() == __rhs._M_base(); }
328
329 template<typename _Key, typename _Tp,
330 typename _Compare, typename _Allocator>
331 inline bool
332 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
333 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
334 { return __lhs._M_base() != __rhs._M_base(); }
335
336 template<typename _Key, typename _Tp,
337 typename _Compare, typename _Allocator>
338 inline bool
339 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
340 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
341 { return __lhs._M_base() < __rhs._M_base(); }
342
343 template<typename _Key, typename _Tp,
344 typename _Compare, typename _Allocator>
345 inline bool
346 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
347 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
348 { return __lhs._M_base() <= __rhs._M_base(); }
349
350 template<typename _Key, typename _Tp,
351 typename _Compare, typename _Allocator>
352 inline bool
353 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
354 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
355 { return __lhs._M_base() >= __rhs._M_base(); }
356
357 template<typename _Key, typename _Tp,
358 typename _Compare, typename _Allocator>
359 inline bool
360 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
361 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
362 { return __lhs._M_base() > __rhs._M_base(); }
363
364 template<typename _Key, typename _Tp,
365 typename _Compare, typename _Allocator>
366 inline void
367 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
368 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
369 { __lhs.swap(__rhs); }
370
371 } // namespace __profile
372 } // namespace std
373
374 #endif