]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/profile/vector
*: Move inside testsuite/21_strings/basic_string/operations/data/.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / vector
CommitLineData
1218d701
SR
1// Profiling vector implementation -*- C++ -*-
2
405feeb8 3// Copyright (C) 2009-2013 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
4bee90f7 8// Free Software Foundation; either version 3, or (at your option)
1218d701 9// any later version.
4bee90f7 10//
1218d701
SR
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.
1889b253
PC
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
1218d701 20// You should have received a copy of the GNU General Public License along
4bee90f7
PC
21// with this library; see the file COPYING3. If not see
22// <http://www.gnu.org/licenses/>.
1218d701
SR
23
24/** @file profile/vector
25 * This file is a GNU profile extension to the Standard C++ Library.
26 */
27
28#ifndef _GLIBCXX_PROFILE_VECTOR
29#define _GLIBCXX_PROFILE_VECTOR 1
30
31#include <vector>
32#include <utility>
33#include <profile/base.h>
a1360f57 34#include <profile/iterator_tracker.h>
1218d701 35
12ffa228 36namespace std _GLIBCXX_VISIBILITY(default)
1218d701
SR
37{
38namespace __profile
39{
1218d701
SR
40 template<typename _Tp,
41 typename _Allocator = std::allocator<_Tp> >
42 class vector
12ffa228 43 : public _GLIBCXX_STD_C::vector<_Tp, _Allocator>
1218d701 44 {
12ffa228 45 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator> _Base;
1218d701 46
734f5023 47#if __cplusplus >= 201103L
42500675
JW
48 typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
49#endif
50
1218d701
SR
51 public:
52 typedef typename _Base::reference reference;
53 typedef typename _Base::const_reference const_reference;
54
a1360f57
SR
55 typedef __iterator_tracker<typename _Base::iterator, vector>
56 iterator;
57 typedef __iterator_tracker<typename _Base::const_iterator, vector>
58 const_iterator;
1218d701
SR
59
60 typedef typename _Base::size_type size_type;
61 typedef typename _Base::difference_type difference_type;
62
a1360f57
SR
63 typedef _Tp value_type;
64 typedef _Allocator allocator_type;
1218d701
SR
65 typedef typename _Base::pointer pointer;
66 typedef typename _Base::const_pointer const_pointer;
a1360f57
SR
67 typedef std::reverse_iterator<iterator> reverse_iterator;
68 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
69
1218d701 70 _Base&
d3677132 71 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
1218d701
SR
72
73 const _Base&
d3677132 74 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
1218d701
SR
75
76 // 23.2.4.1 construct/copy/destroy:
dc2cf706
PC
77 explicit
78 vector(const _Allocator& __a = _Allocator())
1218d701 79 : _Base(__a)
6f59ea25 80 {
1218d701
SR
81 __profcxx_vector_construct(this, this->capacity());
82 __profcxx_vector_construct2(this);
83 }
84
734f5023 85#if __cplusplus >= 201103L
dc2cf706 86 explicit
d720a22b
JW
87 vector(size_type __n, const _Allocator& __a = _Allocator())
88 : _Base(__n, __a)
6f59ea25 89 {
dc2cf706
PC
90 __profcxx_vector_construct(this, this->capacity());
91 __profcxx_vector_construct2(this);
92 }
93
94 vector(size_type __n, const _Tp& __value,
95 const _Allocator& __a = _Allocator())
1218d701 96 : _Base(__n, __value, __a)
6f59ea25 97 {
1218d701
SR
98 __profcxx_vector_construct(this, this->capacity());
99 __profcxx_vector_construct2(this);
100 }
dc2cf706
PC
101#else
102 explicit
103 vector(size_type __n, const _Tp& __value = _Tp(),
104 const _Allocator& __a = _Allocator())
6f59ea25
PC
105 : _Base(__n, __value, __a)
106 {
dc2cf706
PC
107 __profcxx_vector_construct(this, this->capacity());
108 __profcxx_vector_construct2(this);
109 }
110#endif
1218d701 111
734f5023 112#if __cplusplus >= 201103L
3c7d8b03
JW
113 template<typename _InputIterator,
114 typename = std::_RequireInputIter<_InputIterator>>
115#else
116 template<typename _InputIterator>
117#endif
1218d701
SR
118 vector(_InputIterator __first, _InputIterator __last,
119 const _Allocator& __a = _Allocator())
120 : _Base(__first, __last, __a)
6f59ea25
PC
121 {
122 __profcxx_vector_construct(this, this->capacity());
123 __profcxx_vector_construct2(this);
124 }
1218d701
SR
125
126 vector(const vector& __x)
127 : _Base(__x)
6f59ea25 128 {
1218d701
SR
129 __profcxx_vector_construct(this, this->capacity());
130 __profcxx_vector_construct2(this);
131 }
132
133 /// Construction from a release-mode vector
134 vector(const _Base& __x)
135 : _Base(__x)
136 {
137 __profcxx_vector_construct(this, this->capacity());
138 __profcxx_vector_construct2(this);
139 }
140
734f5023 141#if __cplusplus >= 201103L
6f59ea25 142 vector(vector&& __x) noexcept
5f1fd346 143 : _Base(std::move(__x))
1218d701
SR
144 {
145 __profcxx_vector_construct(this, this->capacity());
146 __profcxx_vector_construct2(this);
147 }
148
42500675 149 vector(const _Base& __x, const _Allocator& __a)
d720a22b 150 : _Base(__x, __a)
42500675
JW
151 {
152 __profcxx_vector_construct(this, this->capacity());
153 __profcxx_vector_construct2(this);
154 }
155
156 vector(vector&& __x, const _Allocator& __a) noexcept
157 : _Base(std::move(__x), __a)
158 {
159 __profcxx_vector_construct(this, this->capacity());
160 __profcxx_vector_construct2(this);
161 }
162
1218d701
SR
163 vector(initializer_list<value_type> __l,
164 const allocator_type& __a = allocator_type())
165 : _Base(__l, __a) { }
166#endif
167
6f59ea25 168 ~vector() _GLIBCXX_NOEXCEPT
d3677132 169 {
1218d701
SR
170 __profcxx_vector_destruct(this, this->capacity(), this->size());
171 __profcxx_vector_destruct2(this);
172 }
173
174 vector&
175 operator=(const vector& __x)
176 {
177 static_cast<_Base&>(*this) = __x;
178 return *this;
179 }
180
734f5023 181#if __cplusplus >= 201103L
1218d701 182 vector&
42500675 183 operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
1218d701 184 {
42500675
JW
185 __profcxx_vector_destruct(this, this->capacity(), this->size());
186 __profcxx_vector_destruct2(this);
187 static_cast<_Base&>(*this) = std::move(__x);
0462fd5e 188 return *this;
1218d701
SR
189 }
190
191 vector&
192 operator=(initializer_list<value_type> __l)
193 {
194 static_cast<_Base&>(*this) = __l;
195 return *this;
196 }
197#endif
198
199 using _Base::assign;
200 using _Base::get_allocator;
201
a1360f57
SR
202
203 // iterators:
204 iterator
d3677132 205 begin() _GLIBCXX_NOEXCEPT
a1360f57
SR
206 { return iterator(_Base::begin(), this); }
207
208 const_iterator
d3677132 209 begin() const _GLIBCXX_NOEXCEPT
a1360f57
SR
210 { return const_iterator(_Base::begin(), this); }
211
212 iterator
d3677132 213 end() _GLIBCXX_NOEXCEPT
a1360f57
SR
214 { return iterator(_Base::end(), this); }
215
216 const_iterator
d3677132 217 end() const _GLIBCXX_NOEXCEPT
a1360f57
SR
218 { return const_iterator(_Base::end(), this); }
219
220 reverse_iterator
d3677132 221 rbegin() _GLIBCXX_NOEXCEPT
a1360f57
SR
222 { return reverse_iterator(end()); }
223
224 const_reverse_iterator
d3677132 225 rbegin() const _GLIBCXX_NOEXCEPT
a1360f57
SR
226 { return const_reverse_iterator(end()); }
227
228 reverse_iterator
d3677132 229 rend() _GLIBCXX_NOEXCEPT
a1360f57
SR
230 { return reverse_iterator(begin()); }
231
232 const_reverse_iterator
d3677132 233 rend() const _GLIBCXX_NOEXCEPT
a1360f57
SR
234 { return const_reverse_iterator(begin()); }
235
734f5023 236#if __cplusplus >= 201103L
a1360f57 237 const_iterator
d3677132 238 cbegin() const noexcept
a1360f57
SR
239 { return const_iterator(_Base::begin(), this); }
240
241 const_iterator
d3677132 242 cend() const noexcept
a1360f57
SR
243 { return const_iterator(_Base::end(), this); }
244
245 const_reverse_iterator
d3677132 246 crbegin() const noexcept
a1360f57
SR
247 { return const_reverse_iterator(end()); }
248
249 const_reverse_iterator
d3677132 250 crend() const noexcept
a1360f57
SR
251 { return const_reverse_iterator(begin()); }
252#endif
253
1218d701
SR
254 // 23.2.4.2 capacity:
255 using _Base::size;
256 using _Base::max_size;
257
734f5023 258#if __cplusplus >= 201103L
dc2cf706
PC
259 void
260 resize(size_type __sz)
261 {
262 __profcxx_vector_invalid_operator(this);
263 _M_profile_resize(this, this->capacity(), __sz);
264 _Base::resize(__sz);
265 }
266
267 void
268 resize(size_type __sz, const _Tp& __c)
269 {
270 __profcxx_vector_invalid_operator(this);
271 _M_profile_resize(this, this->capacity(), __sz);
272 _Base::resize(__sz, __c);
273 }
274#else
1218d701
SR
275 void
276 resize(size_type __sz, _Tp __c = _Tp())
277 {
278 __profcxx_vector_invalid_operator(this);
279 _M_profile_resize(this, this->capacity(), __sz);
280 _Base::resize(__sz, __c);
281 }
dc2cf706 282#endif
1218d701 283
734f5023 284#if __cplusplus >= 201103L
79667f82
PC
285 using _Base::shrink_to_fit;
286#endif
287
1218d701
SR
288 using _Base::empty;
289
290 // element access:
291 reference
292 operator[](size_type __n)
293 {
294 __profcxx_vector_invalid_operator(this);
295 return _M_base()[__n];
296 }
297 const_reference
298 operator[](size_type __n) const
299 {
300 __profcxx_vector_invalid_operator(this);
301 return _M_base()[__n];
302 }
303
304 using _Base::at;
305
306 reference
307 front()
308 {
309 return _Base::front();
310 }
311
312 const_reference
313 front() const
314 {
315 return _Base::front();
316 }
317
318 reference
319 back()
320 {
321 return _Base::back();
322 }
323
324 const_reference
325 back() const
326 {
327 return _Base::back();
328 }
329
330 // _GLIBCXX_RESOLVE_LIB_DEFECTS
331 // DR 464. Suggestion for new member functions in standard containers.
332 using _Base::data;
333
334 // 23.2.4.3 modifiers:
335 void
336 push_back(const _Tp& __x)
337 {
338 size_type __old_size = this->capacity();
339 _Base::push_back(__x);
340 _M_profile_resize(this, __old_size, this->capacity());
341 }
342
734f5023 343#if __cplusplus >= 201103L
1218d701
SR
344 void
345 push_back(_Tp&& __x)
346 {
347 size_type __old_size = this->capacity();
42500675 348 _Base::push_back(std::move(__x));
1218d701
SR
349 _M_profile_resize(this, __old_size, this->capacity());
350 }
351
352#endif
353
354 iterator
7b61c5a9
PC
355#if __cplusplus >= 201103L
356 insert(const_iterator __position, const _Tp& __x)
357#else
1218d701 358 insert(iterator __position, const _Tp& __x)
7b61c5a9 359#endif
1218d701 360 {
a1360f57
SR
361 __profcxx_vector_insert(this, __position.base() - _Base::begin(),
362 this->size());
1218d701 363 size_type __old_size = this->capacity();
a1360f57 364 typename _Base::iterator __res = _Base::insert(__position.base(), __x);
1218d701 365 _M_profile_resize(this, __old_size, this->capacity());
a1360f57 366 return iterator(__res, this);
1218d701
SR
367 }
368
734f5023 369#if __cplusplus >= 201103L
1218d701 370 iterator
7b61c5a9 371 insert(const_iterator __position, _Tp&& __x)
1218d701 372 {
a1360f57
SR
373 __profcxx_vector_insert(this, __position.base() - _Base::begin(),
374 this->size());
1218d701 375 size_type __old_size = this->capacity();
a1360f57 376 typename _Base::iterator __res = _Base::insert(__position.base(), __x);
1218d701 377 _M_profile_resize(this, __old_size, this->capacity());
a1360f57 378 return iterator(__res, this);
1218d701
SR
379 }
380
7b61c5a9
PC
381 template<typename... _Args>
382 iterator
383 emplace(const_iterator __position, _Args&&... __args)
384 {
385 typename _Base::iterator __res
386 = _Base::emplace(__position.base(),
387 std::forward<_Args>(__args)...);
388 return iterator(__res, this);
389 }
390
1218d701
SR
391 void
392 insert(iterator __position, initializer_list<value_type> __l)
393 { this->insert(__position, __l.begin(), __l.end()); }
394#endif
395
734f5023 396#if __cplusplus >= 201103L
1218d701 397 void
a1360f57
SR
398 swap(vector&& __x)
399 {
400 _Base::swap(__x);
401 }
402#endif
1218d701 403
a1360f57 404 void
1218d701 405 swap(vector& __x)
734f5023 406#if __cplusplus >= 201103L
42500675
JW
407 noexcept(_Alloc_traits::_S_nothrow_swap())
408#endif
1218d701
SR
409 {
410 _Base::swap(__x);
411 }
412
1218d701
SR
413 void
414 insert(iterator __position, size_type __n, const _Tp& __x)
415 {
a1360f57
SR
416 __profcxx_vector_insert(this, __position.base() - _Base::begin(),
417 this->size());
1218d701 418 size_type __old_size = this->capacity();
a1360f57 419 _Base::insert(__position, __n, __x);
1218d701
SR
420 _M_profile_resize(this, __old_size, this->capacity());
421 }
422
734f5023 423#if __cplusplus >= 201103L
3c7d8b03
JW
424 template<typename _InputIterator,
425 typename = std::_RequireInputIter<_InputIterator>>
426#else
427 template<typename _InputIterator>
428#endif
1218d701
SR
429 void
430 insert(iterator __position,
431 _InputIterator __first, _InputIterator __last)
432 {
a1360f57
SR
433 __profcxx_vector_insert(this, __position.base()-_Base::begin(),
434 this->size());
1218d701
SR
435 size_type __old_size = this->capacity();
436 _Base::insert(__position, __first, __last);
437 _M_profile_resize(this, __old_size, this->capacity());
438 }
439
a1360f57 440 iterator
94938aec
PC
441#if __cplusplus >= 201103L
442 erase(const_iterator __position)
443#else
444 erase(iterator __position)
445#endif
a1360f57
SR
446 {
447 typename _Base::iterator __res = _Base::erase(__position.base());
448 return iterator(__res, this);
449 }
450
451 iterator
94938aec
PC
452#if __cplusplus >= 201103L
453 erase(const_iterator __first, const_iterator __last)
454#else
a1360f57 455 erase(iterator __first, iterator __last)
94938aec 456#endif
a1360f57
SR
457 {
458 // _GLIBCXX_RESOLVE_LIB_DEFECTS
459 // 151. can't currently clear() empty container
460 typename _Base::iterator __res = _Base::erase(__first.base(),
461 __last.base());
462 return iterator(__res, this);
463 }
464
1218d701 465 void
d3677132 466 clear() _GLIBCXX_NOEXCEPT
1218d701
SR
467 {
468 __profcxx_vector_destruct(this, this->capacity(), this->size());
469 __profcxx_vector_destruct2(this);
470 _Base::clear();
471 }
472
a1360f57 473 inline void _M_profile_find() const
1218d701 474 {
a1360f57 475 __profcxx_vector_find(this, size());
1218d701
SR
476 }
477
a1360f57 478 inline void _M_profile_iterate(int __rewind = 0) const
1218d701 479 {
a1360f57 480 __profcxx_vector_iterate(this);
1218d701
SR
481 }
482
483 private:
484 void _M_profile_resize(void* obj, size_type __old_size,
485 size_type __new_size)
486 {
487 if (__old_size < __new_size) {
488 __profcxx_vector_resize(this, this->size(), __new_size);
489 __profcxx_vector_resize2(this, this->size(), __new_size);
490 }
491 }
492 };
493
494 template<typename _Tp, typename _Alloc>
495 inline bool
496 operator==(const vector<_Tp, _Alloc>& __lhs,
497 const vector<_Tp, _Alloc>& __rhs)
498 { return __lhs._M_base() == __rhs._M_base(); }
499
500 template<typename _Tp, typename _Alloc>
501 inline bool
502 operator!=(const vector<_Tp, _Alloc>& __lhs,
503 const vector<_Tp, _Alloc>& __rhs)
504 { return __lhs._M_base() != __rhs._M_base(); }
505
506 template<typename _Tp, typename _Alloc>
507 inline bool
508 operator<(const vector<_Tp, _Alloc>& __lhs,
509 const vector<_Tp, _Alloc>& __rhs)
510 { return __lhs._M_base() < __rhs._M_base(); }
511
512 template<typename _Tp, typename _Alloc>
513 inline bool
514 operator<=(const vector<_Tp, _Alloc>& __lhs,
515 const vector<_Tp, _Alloc>& __rhs)
516 { return __lhs._M_base() <= __rhs._M_base(); }
517
518 template<typename _Tp, typename _Alloc>
519 inline bool
520 operator>=(const vector<_Tp, _Alloc>& __lhs,
521 const vector<_Tp, _Alloc>& __rhs)
522 { return __lhs._M_base() >= __rhs._M_base(); }
523
524 template<typename _Tp, typename _Alloc>
525 inline bool
526 operator>(const vector<_Tp, _Alloc>& __lhs,
527 const vector<_Tp, _Alloc>& __rhs)
528 { return __lhs._M_base() > __rhs._M_base(); }
529
530 template<typename _Tp, typename _Alloc>
531 inline void
532 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
533 { __lhs.swap(__rhs); }
534
734f5023 535#if __cplusplus >= 201103L
a1360f57
SR
536 template<typename _Tp, typename _Alloc>
537 inline void
538 swap(vector<_Tp, _Alloc>&& __lhs, vector<_Tp, _Alloc>& __rhs)
539 { __lhs.swap(__rhs); }
540
541 template<typename _Tp, typename _Alloc>
542 inline void
543 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>&& __rhs)
544 { __lhs.swap(__rhs); }
545#endif
546
1218d701 547} // namespace __profile
4cd533a7 548
734f5023 549#if __cplusplus >= 201103L
4cd533a7
PC
550 // DR 1182.
551 /// std::hash specialization for vector<bool>.
552 template<typename _Alloc>
553 struct hash<__profile::vector<bool, _Alloc>>
5d64ee19 554 : public __hash_base<size_t, __profile::vector<bool, _Alloc>>
4cd533a7
PC
555 {
556 size_t
72f1c34b 557 operator()(const __profile::vector<bool, _Alloc>& __b) const noexcept
12ffa228 558 { return std::hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>()
4cd533a7
PC
559 (__b._M_base()); }
560 };
561#endif
562
1218d701
SR
563} // namespace std
564
565#endif