]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/profile/set.h
array: Clean useless white chars.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / set.h
CommitLineData
1218d701
SR
1// Profiling set implementation -*- C++ -*-
2
aa118a03 3// Copyright (C) 2009-2014 Free Software Foundation, Inc.
1218d701
SR
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/set.h
26 * This file is a GNU profile extension to the Standard C++ Library.
27 */
28
29#ifndef _GLIBCXX_PROFILE_SET_H
30#define _GLIBCXX_PROFILE_SET_H 1
31
f3de79d4
FD
32#include <profile/base.h>
33#include <profile/ordered_base.h>
1218d701 34
f3de79d4 35namespace std _GLIBCXX_VISIBILITY(default)
1218d701
SR
36{
37namespace __profile
38{
9ee6a740 39 /// Class std::set wrapper with performance instrumentation.
1218d701
SR
40 template<typename _Key, typename _Compare = std::less<_Key>,
41 typename _Allocator = std::allocator<_Key> >
42 class set
f3de79d4
FD
43 : public _GLIBCXX_STD_C::set<_Key,_Compare,_Allocator>,
44 public _Ordered_profile<set<_Key, _Compare, _Allocator> >
1218d701 45 {
12ffa228 46 typedef _GLIBCXX_STD_C::set<_Key, _Compare, _Allocator> _Base;
1218d701 47
1217ee06
FD
48#if __cplusplus >= 201103L
49 typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
50#endif
51
1218d701
SR
52 public:
53 // types:
f3de79d4
FD
54 typedef _Key key_type;
55 typedef _Key value_type;
56 typedef _Compare key_compare;
57 typedef _Compare value_compare;
58 typedef typename _Base::reference reference;
59 typedef typename _Base::const_reference const_reference;
60
61 typedef typename _Base::iterator iterator;
62 typedef typename _Base::const_iterator const_iterator;
63 typedef typename _Base::reverse_iterator reverse_iterator;
64 typedef typename _Base::const_reverse_iterator const_reverse_iterator;
65
66 typedef typename _Base::size_type size_type;
67 typedef typename _Base::difference_type difference_type;
68 typedef typename _Base::pointer pointer;
69 typedef typename _Base::const_pointer const_pointer;
1218d701
SR
70
71 // 23.3.3.1 construct/copy/destroy:
f3de79d4 72#if __cplusplus < 201103L
c3cdd71f
JW
73 set()
74 : _Base() { }
f3de79d4
FD
75 set(const set& __x)
76 : _Base(__x) { }
77 ~set() { }
78#else
79 set() = default;
80 set(const set&) = default;
81 set(set&&) = default;
82 ~set() = default;
83#endif
c3cdd71f
JW
84
85 explicit set(const _Compare& __comp,
1218d701
SR
86 const _Allocator& __a = _Allocator())
87 : _Base(__comp, __a) { }
88
734f5023 89#if __cplusplus >= 201103L
3c7d8b03
JW
90 template<typename _InputIterator,
91 typename = std::_RequireInputIter<_InputIterator>>
92#else
1218d701 93 template<typename _InputIterator>
3c7d8b03 94#endif
f3de79d4 95 set(_InputIterator __first, _InputIterator __last,
1218d701
SR
96 const _Compare& __comp = _Compare(),
97 const _Allocator& __a = _Allocator())
98 : _Base(__first, __last, __comp, __a) { }
99
f3de79d4 100#if __cplusplus >= 201103L
1218d701
SR
101 set(initializer_list<value_type> __l,
102 const _Compare& __comp = _Compare(),
f3de79d4 103 const _Allocator& __a = _Allocator())
1218d701 104 : _Base(__l, __comp, __a) { }
1217ee06
FD
105
106 explicit
f3de79d4
FD
107 set(const _Allocator& __a)
108 : _Base(__a) { }
1217ee06 109
f3de79d4 110 set(const set& __x, const _Allocator& __a)
1217ee06
FD
111 : _Base(__x, __a) { }
112
f3de79d4
FD
113 set(set&& __x, const _Allocator& __a)
114 noexcept( noexcept(_Base(std::move(__x), __a)) )
1217ee06
FD
115 : _Base(std::move(__x), __a) { }
116
f3de79d4 117 set(initializer_list<value_type> __l, const _Allocator& __a)
1217ee06
FD
118 : _Base(__l, __a) { }
119
120 template<typename _InputIterator>
f3de79d4
FD
121 set(_InputIterator __first, _InputIterator __last,
122 const _Allocator& __a)
123 : _Base(__first, __last, __a) { }
1218d701
SR
124#endif
125
1217ee06
FD
126 set(const _Base& __x)
127 : _Base(__x) { }
128
1217ee06 129#if __cplusplus < 201103L
1218d701
SR
130 set&
131 operator=(const set& __x)
132 {
1217ee06 133 _M_base() = __x;
1218d701
SR
134 return *this;
135 }
1217ee06
FD
136#else
137 set&
138 operator=(const set&) = default;
1218d701 139
1218d701 140 set&
1217ee06 141 operator=(set&&) = default;
1218d701
SR
142
143 set&
144 operator=(initializer_list<value_type> __l)
145 {
1217ee06 146 _M_base() = __l;
1218d701
SR
147 return *this;
148 }
149#endif
150
1218d701 151 reverse_iterator
d3677132 152 rbegin() _GLIBCXX_NOEXCEPT
f3de79d4
FD
153 {
154 __profcxx_map_to_unordered_map_invalidate(this);
155 return _Base::rbegin();
156 }
1218d701
SR
157
158 const_reverse_iterator
d3677132 159 rbegin() const _GLIBCXX_NOEXCEPT
f3de79d4
FD
160 {
161 __profcxx_map_to_unordered_map_invalidate(this);
162 return _Base::rbegin();
163 }
1218d701
SR
164
165 reverse_iterator
d3677132 166 rend() _GLIBCXX_NOEXCEPT
f3de79d4
FD
167 {
168 __profcxx_map_to_unordered_map_invalidate(this);
169 return _Base::rend();
170 }
1218d701
SR
171
172 const_reverse_iterator
d3677132 173 rend() const _GLIBCXX_NOEXCEPT
f3de79d4
FD
174 {
175 __profcxx_map_to_unordered_map_invalidate(this);
176 return _Base::rend();
177 }
1218d701 178
734f5023 179#if __cplusplus >= 201103L
1218d701 180 const_reverse_iterator
d3677132 181 crbegin() const noexcept
f3de79d4
FD
182 {
183 __profcxx_map_to_unordered_map_invalidate(this);
184 return _Base::crbegin();
185 }
1218d701
SR
186
187 const_reverse_iterator
d3677132 188 crend() const noexcept
f3de79d4
FD
189 {
190 __profcxx_map_to_unordered_map_invalidate(this);
191 return _Base::crend();
192 }
1218d701
SR
193#endif
194
1218d701 195 // modifiers:
734f5023 196#if __cplusplus >= 201103L
55826ab6
FD
197 template<typename... _Args>
198 std::pair<iterator, bool>
199 emplace(_Args&&... __args)
200 {
f3de79d4
FD
201 __profcxx_map_to_unordered_map_insert(this, this->size(), 1);
202 return _Base::emplace(std::forward<_Args>(__args)...);
55826ab6
FD
203 }
204
205 template<typename... _Args>
206 iterator
207 emplace_hint(const_iterator __pos, _Args&&... __args)
208 {
f3de79d4
FD
209 auto size_before = this->size();
210 auto __res
211 = _Base::emplace_hint(__pos, std::forward<_Args>(__args)...);
212 __profcxx_map_to_unordered_map_insert(this, size_before,
213 _M_hint_used(__pos, __res) ? 0 : 1);
214 return __res;
55826ab6
FD
215 }
216#endif
217
1218d701
SR
218 std::pair<iterator, bool>
219 insert(const value_type& __x)
220 {
f3de79d4
FD
221 __profcxx_map_to_unordered_map_insert(this, this->size(), 1);
222 return _Base::insert(__x);
1218d701
SR
223 }
224
734f5023 225#if __cplusplus >= 201103L
e6a05448
PC
226 std::pair<iterator, bool>
227 insert(value_type&& __x)
228 {
f3de79d4
FD
229 __profcxx_map_to_unordered_map_insert(this, this->size(), 1);
230 return _Base::insert(std::move(__x));
e6a05448
PC
231 }
232#endif
233
1218d701 234 iterator
f3de79d4
FD
235 insert(const_iterator __pos, const value_type& __x)
236 {
237 size_type size_before = this->size();
238 iterator __res = _Base::insert(__pos, __x);
239 __profcxx_map_to_unordered_map_insert(this, size_before,
240 _M_hint_used(__pos, __res) ? 0 : 1);
241 return __res;
242 }
1218d701 243
734f5023 244#if __cplusplus >= 201103L
e6a05448
PC
245 iterator
246 insert(const_iterator __position, value_type&& __x)
247 { return iterator(_Base::insert(__position, std::move(__x))); }
248#endif
249
734f5023 250#if __cplusplus >= 201103L
3c7d8b03
JW
251 template<typename _InputIterator,
252 typename = std::_RequireInputIter<_InputIterator>>
253#else
254 template<typename _InputIterator>
255#endif
f3de79d4
FD
256 void
257 insert(_InputIterator __first, _InputIterator __last)
258 {
259 for (; __first != __last; ++__first)
260 insert(*__first);
261 }
1218d701 262
734f5023 263#if __cplusplus >= 201103L
1218d701
SR
264 void
265 insert(initializer_list<value_type> __l)
f3de79d4 266 { insert(__l.begin(), __l.end()); }
1218d701
SR
267#endif
268
734f5023 269#if __cplusplus >= 201103L
1218d701 270 iterator
f3de79d4
FD
271 erase(const_iterator __pos)
272 {
273 __profcxx_map_to_unordered_map_erase(this, this->size(), 1);
274 return _Base::erase(__pos);
275 }
1218d701
SR
276#else
277 void
f3de79d4
FD
278 erase(iterator __pos)
279 {
280 __profcxx_map_to_unordered_map_erase(this, this->size(), 1);
281 _Base::erase(__pos);
282 }
1218d701
SR
283#endif
284
285 size_type
286 erase(const key_type& __x)
287 {
f3de79d4
FD
288 __profcxx_map_to_unordered_map_find(this, this->size());
289 __profcxx_map_to_unordered_map_erase(this, this->size(), 1);
290 return _Base::erase(__x);
1218d701
SR
291 }
292
734f5023 293#if __cplusplus >= 201103L
5ab06c6d 294 iterator
7606bd11 295 erase(const_iterator __first, const_iterator __last)
f3de79d4
FD
296 {
297 if (__first != __last)
298 {
299 iterator __ret;
300 for (; __first != __last;)
301 __ret = erase(__first++);
302 return __ret;
303 }
304
305 return _Base::erase(__first, __last);
306 }
5ab06c6d 307#else
1218d701
SR
308 void
309 erase(iterator __first, iterator __last)
f3de79d4
FD
310 {
311 for (; __first != __last;)
312 erase(__first++);
313 }
5ab06c6d 314#endif
1218d701
SR
315
316 void
317 swap(set& __x)
1217ee06 318#if __cplusplus >= 201103L
f3de79d4 319 noexcept( noexcept(declval<_Base>().swap(__x)) )
1217ee06 320#endif
7606bd11 321 { _Base::swap(__x); }
1218d701 322
1218d701
SR
323 // set operations:
324 iterator
325 find(const key_type& __x)
f3de79d4
FD
326 {
327 __profcxx_map_to_unordered_map_find(this, this->size());
328 return _Base::find(__x);
329 }
1218d701 330
1218d701
SR
331 const_iterator
332 find(const key_type& __x) const
f3de79d4
FD
333 {
334 __profcxx_map_to_unordered_map_find(this, this->size());
335 return _Base::find(__x);
336 }
1218d701 337
f3de79d4
FD
338 size_type
339 count(const key_type& __x) const
340 {
341 __profcxx_map_to_unordered_map_find(this, this->size());
342 return _Base::count(__x);
343 }
1218d701
SR
344
345 iterator
346 lower_bound(const key_type& __x)
f3de79d4
FD
347 {
348 __profcxx_map_to_unordered_map_find(this, this->size());
349 __profcxx_map_to_unordered_map_invalidate(this);
350 return _Base::lower_bound(__x);
351 }
1218d701 352
1218d701
SR
353 const_iterator
354 lower_bound(const key_type& __x) const
f3de79d4
FD
355 {
356 __profcxx_map_to_unordered_map_find(this, this->size());
357 __profcxx_map_to_unordered_map_invalidate(this);
358 return _Base::lower_bound(__x);
359 }
1218d701
SR
360
361 iterator
362 upper_bound(const key_type& __x)
f3de79d4
FD
363 {
364 __profcxx_map_to_unordered_map_find(this, this->size());
365 __profcxx_map_to_unordered_map_invalidate(this);
366 return _Base::upper_bound(__x);
367 }
1218d701 368
1218d701
SR
369 const_iterator
370 upper_bound(const key_type& __x) const
f3de79d4
FD
371 {
372 __profcxx_map_to_unordered_map_find(this, this->size());
373 __profcxx_map_to_unordered_map_invalidate(this);
374 return _Base::upper_bound(__x);
375 }
1218d701 376
f3de79d4 377 std::pair<iterator, iterator>
1218d701
SR
378 equal_range(const key_type& __x)
379 {
f3de79d4
FD
380 __profcxx_map_to_unordered_map_find(this, this->size());
381 return _Base::equal_range(__x);
1218d701
SR
382 }
383
f3de79d4 384 std::pair<const_iterator, const_iterator>
1218d701
SR
385 equal_range(const key_type& __x) const
386 {
f3de79d4
FD
387 __profcxx_map_to_unordered_map_find(this, this->size());
388 return _Base::equal_range(__x);
1218d701
SR
389 }
390
391 _Base&
f3de79d4 392 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
1218d701
SR
393
394 const _Base&
f3de79d4
FD
395 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
396
397 private:
398 /** If hint is used we consider that the map and unordered_map
399 * operations have equivalent insertion cost so we do not update metrics
400 * about it.
401 * Note that to find out if hint has been used is libstdc++
402 * implementation dependant.
403 */
404 bool
405 _M_hint_used(const_iterator __hint, iterator __res)
406 {
407 return (__hint == __res ||
408 (__hint == this->end() && ++__res == this->end()) ||
409 (__hint != this->end() && (++__hint == __res ||
410 ++__res == --__hint)));
411 }
1218d701
SR
412 };
413
414 template<typename _Key, typename _Compare, typename _Allocator>
415 inline bool
416 operator==(const set<_Key, _Compare, _Allocator>& __lhs,
417 const set<_Key, _Compare, _Allocator>& __rhs)
418 { return __lhs._M_base() == __rhs._M_base(); }
419
420 template<typename _Key, typename _Compare, typename _Allocator>
421 inline bool
422 operator!=(const set<_Key, _Compare, _Allocator>& __lhs,
423 const set<_Key, _Compare, _Allocator>& __rhs)
424 { return __lhs._M_base() != __rhs._M_base(); }
425
426 template<typename _Key, typename _Compare, typename _Allocator>
427 inline bool
428 operator<(const set<_Key, _Compare, _Allocator>& __lhs,
429 const set<_Key, _Compare, _Allocator>& __rhs)
430 { return __lhs._M_base() < __rhs._M_base(); }
431
432 template<typename _Key, typename _Compare, typename _Allocator>
433 inline bool
434 operator<=(const set<_Key, _Compare, _Allocator>& __lhs,
435 const set<_Key, _Compare, _Allocator>& __rhs)
436 { return __lhs._M_base() <= __rhs._M_base(); }
437
438 template<typename _Key, typename _Compare, typename _Allocator>
439 inline bool
440 operator>=(const set<_Key, _Compare, _Allocator>& __lhs,
441 const set<_Key, _Compare, _Allocator>& __rhs)
442 { return __lhs._M_base() >= __rhs._M_base(); }
443
444 template<typename _Key, typename _Compare, typename _Allocator>
445 inline bool
446 operator>(const set<_Key, _Compare, _Allocator>& __lhs,
447 const set<_Key, _Compare, _Allocator>& __rhs)
448 { return __lhs._M_base() > __rhs._M_base(); }
449
450 template<typename _Key, typename _Compare, typename _Allocator>
451 void
452 swap(set<_Key, _Compare, _Allocator>& __x,
453 set<_Key, _Compare, _Allocator>& __y)
454 { return __x.swap(__y); }
455
456} // namespace __profile
457} // namespace std
458
459#endif