xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/profile/vector (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj// Profiling vector implementation -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj// Copyright (C) 2009-2018 Free Software Foundation, Inc.
4*38fd1498Szrj//
5*38fd1498Szrj// This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj// software; you can redistribute it and/or modify it under the
7*38fd1498Szrj// terms of the GNU General Public License as published by the
8*38fd1498Szrj// Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj// any later version.
10*38fd1498Szrj//
11*38fd1498Szrj// This library is distributed in the hope that it will be useful,
12*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj// GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj// 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj// You should have received a copy of the GNU General Public License along
21*38fd1498Szrj// with this library; see the file COPYING3.  If not see
22*38fd1498Szrj// <http://www.gnu.org/licenses/>.
23*38fd1498Szrj
24*38fd1498Szrj/** @file profile/vector
25*38fd1498Szrj *  This file is a GNU profile extension to the Standard C++ Library.
26*38fd1498Szrj */
27*38fd1498Szrj
28*38fd1498Szrj#ifndef _GLIBCXX_PROFILE_VECTOR
29*38fd1498Szrj#define _GLIBCXX_PROFILE_VECTOR 1
30*38fd1498Szrj
31*38fd1498Szrj#include <vector>
32*38fd1498Szrj#include <utility>
33*38fd1498Szrj#include <profile/base.h>
34*38fd1498Szrj#include <profile/iterator_tracker.h>
35*38fd1498Szrj
36*38fd1498Szrjnamespace std _GLIBCXX_VISIBILITY(default)
37*38fd1498Szrj{
38*38fd1498Szrjnamespace __profile
39*38fd1498Szrj{
40*38fd1498Szrj  template<typename _Vector>
41*38fd1498Szrj    class _Vector_profile_pre
42*38fd1498Szrj    {
43*38fd1498Szrj      _Vector&
44*38fd1498Szrj      _M_conjure()
45*38fd1498Szrj      { return *static_cast<_Vector*>(this); }
46*38fd1498Szrj
47*38fd1498Szrj    public:
48*38fd1498Szrj#if __cplusplus >= 201103L
49*38fd1498Szrj      _Vector_profile_pre() = default;
50*38fd1498Szrj      _Vector_profile_pre(const _Vector_profile_pre&) = default;
51*38fd1498Szrj      _Vector_profile_pre(_Vector_profile_pre&&) = default;
52*38fd1498Szrj
53*38fd1498Szrj      _Vector_profile_pre&
54*38fd1498Szrj      operator=(const _Vector_profile_pre&)
55*38fd1498Szrj      { _M_conjure()._M_profile_destruct(); }
56*38fd1498Szrj
57*38fd1498Szrj      _Vector_profile_pre&
58*38fd1498Szrj      operator=(_Vector_profile_pre&&) noexcept
59*38fd1498Szrj      { _M_conjure()._M_profile_destruct(); }
60*38fd1498Szrj#endif
61*38fd1498Szrj    };
62*38fd1498Szrj
63*38fd1498Szrj  template<typename _Vector>
64*38fd1498Szrj    class _Vector_profile_post
65*38fd1498Szrj    {
66*38fd1498Szrj      _Vector&
67*38fd1498Szrj      _M_conjure()
68*38fd1498Szrj      { return *static_cast<_Vector*>(this); }
69*38fd1498Szrj
70*38fd1498Szrj    protected:
71*38fd1498Szrj      __gnu_profile::__container_size_info* _M_size_info;
72*38fd1498Szrj      __gnu_profile::__vector2list_info* _M_vect2list_info;
73*38fd1498Szrj
74*38fd1498Szrj      _Vector_profile_post() _GLIBCXX_NOEXCEPT
75*38fd1498Szrj      { _M_profile_construct(); }
76*38fd1498Szrj
77*38fd1498Szrj#if __cplusplus >= 201103L
78*38fd1498Szrj      _Vector_profile_post(const _Vector_profile_post&) noexcept
79*38fd1498Szrj      : _Vector_profile_post() { }
80*38fd1498Szrj      _Vector_profile_post(_Vector_profile_post&& __other) noexcept
81*38fd1498Szrj      : _Vector_profile_post()
82*38fd1498Szrj      { _M_swap(__other); }
83*38fd1498Szrj
84*38fd1498Szrj      _Vector_profile_post&
85*38fd1498Szrj      operator=(const _Vector_profile_post&) noexcept
86*38fd1498Szrj      { _M_profile_construct(); }
87*38fd1498Szrj
88*38fd1498Szrj      _Vector_profile_post&
89*38fd1498Szrj      operator=(_Vector_profile_post&& __other) noexcept
90*38fd1498Szrj      {
91*38fd1498Szrj	_M_swap(__other);
92*38fd1498Szrj	__other._M_profile_construct();
93*38fd1498Szrj      }
94*38fd1498Szrj#endif
95*38fd1498Szrj
96*38fd1498Szrj      ~_Vector_profile_post()
97*38fd1498Szrj      { _M_conjure()._M_profile_destruct(); }
98*38fd1498Szrj
99*38fd1498Szrj    public:
100*38fd1498Szrj      void
101*38fd1498Szrj      _M_profile_construct() _GLIBCXX_NOEXCEPT
102*38fd1498Szrj      {
103*38fd1498Szrj	_M_size_info =
104*38fd1498Szrj	  __profcxx_vector_size_construct(_M_conjure().capacity());
105*38fd1498Szrj	_M_vect2list_info = __profcxx_vector2list_construct();
106*38fd1498Szrj      }
107*38fd1498Szrj
108*38fd1498Szrj      void
109*38fd1498Szrj      _M_profile_destruct() _GLIBCXX_NOEXCEPT
110*38fd1498Szrj      {
111*38fd1498Szrj	__profcxx_vector2list_destruct(_M_vect2list_info);
112*38fd1498Szrj	_M_vect2list_info = 0;
113*38fd1498Szrj	__profcxx_vector_size_destruct(_M_size_info,
114*38fd1498Szrj				       _M_conjure().capacity(),
115*38fd1498Szrj				       _M_conjure().size());
116*38fd1498Szrj	_M_size_info = 0;
117*38fd1498Szrj      }
118*38fd1498Szrj
119*38fd1498Szrj      void
120*38fd1498Szrj      _M_swap(_Vector_profile_post& __other) _GLIBCXX_NOEXCEPT
121*38fd1498Szrj      {
122*38fd1498Szrj	std::swap(_M_size_info, __other._M_size_info);
123*38fd1498Szrj	std::swap(_M_vect2list_info, __other._M_vect2list_info);
124*38fd1498Szrj      }
125*38fd1498Szrj    };
126*38fd1498Szrj
127*38fd1498Szrj  template<typename _Tp,
128*38fd1498Szrj	   typename _Allocator = std::allocator<_Tp> >
129*38fd1498Szrj    class vector
130*38fd1498Szrj    : public _Vector_profile_pre<vector<_Tp, _Allocator> >,
131*38fd1498Szrj      public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
132*38fd1498Szrj      public _Vector_profile_post<vector<_Tp, _Allocator> >
133*38fd1498Szrj    {
134*38fd1498Szrj      typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>	_Base;
135*38fd1498Szrj
136*38fd1498Szrj      typedef typename _Base::iterator			_Base_iterator;
137*38fd1498Szrj      typedef typename _Base::const_iterator		_Base_const_iterator;
138*38fd1498Szrj
139*38fd1498Szrj    public:
140*38fd1498Szrj      typedef typename _Base::reference			reference;
141*38fd1498Szrj      typedef typename _Base::const_reference		const_reference;
142*38fd1498Szrj
143*38fd1498Szrj      typedef __iterator_tracker<_Base_iterator, vector>
144*38fd1498Szrj							iterator;
145*38fd1498Szrj      typedef __iterator_tracker<_Base_const_iterator, vector>
146*38fd1498Szrj							const_iterator;
147*38fd1498Szrj
148*38fd1498Szrj      typedef typename _Base::size_type			size_type;
149*38fd1498Szrj      typedef typename _Base::difference_type		difference_type;
150*38fd1498Szrj
151*38fd1498Szrj      typedef _Tp					value_type;
152*38fd1498Szrj      typedef _Allocator				allocator_type;
153*38fd1498Szrj      typedef typename _Base::pointer			pointer;
154*38fd1498Szrj      typedef typename _Base::const_pointer		const_pointer;
155*38fd1498Szrj      typedef std::reverse_iterator<iterator>		reverse_iterator;
156*38fd1498Szrj      typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
157*38fd1498Szrj
158*38fd1498Szrj      _Base&
159*38fd1498Szrj      _M_base() _GLIBCXX_NOEXCEPT	{ return *this; }
160*38fd1498Szrj
161*38fd1498Szrj      const _Base&
162*38fd1498Szrj      _M_base() const _GLIBCXX_NOEXCEPT	{ return *this; }
163*38fd1498Szrj
164*38fd1498Szrj      // 23.2.4.1 construct/copy/destroy:
165*38fd1498Szrj
166*38fd1498Szrj#if __cplusplus < 201103L
167*38fd1498Szrj      vector()
168*38fd1498Szrj      { }
169*38fd1498Szrj
170*38fd1498Szrj      vector(const vector& __x)
171*38fd1498Szrj      : _Base(__x) { }
172*38fd1498Szrj#else
173*38fd1498Szrj      vector() = default;
174*38fd1498Szrj      vector(const vector&) = default;
175*38fd1498Szrj      vector(vector&&) = default;
176*38fd1498Szrj#endif
177*38fd1498Szrj
178*38fd1498Szrj      explicit
179*38fd1498Szrj      vector(const _Allocator& __a) _GLIBCXX_NOEXCEPT
180*38fd1498Szrj      : _Base(__a) { }
181*38fd1498Szrj
182*38fd1498Szrj#if __cplusplus >= 201103L
183*38fd1498Szrj      explicit
184*38fd1498Szrj      vector(size_type __n, const _Allocator& __a = _Allocator())
185*38fd1498Szrj      : _Base(__n, __a) { }
186*38fd1498Szrj
187*38fd1498Szrj      vector(size_type __n, const _Tp& __value,
188*38fd1498Szrj	     const _Allocator& __a = _Allocator())
189*38fd1498Szrj      : _Base(__n, __value, __a) { }
190*38fd1498Szrj#else
191*38fd1498Szrj      explicit
192*38fd1498Szrj      vector(size_type __n, const _Tp& __value = _Tp(),
193*38fd1498Szrj	     const _Allocator& __a = _Allocator())
194*38fd1498Szrj      : _Base(__n, __value, __a) { }
195*38fd1498Szrj#endif
196*38fd1498Szrj
197*38fd1498Szrj#if __cplusplus >= 201103L
198*38fd1498Szrj      template<typename _InputIterator,
199*38fd1498Szrj	       typename = std::_RequireInputIter<_InputIterator>>
200*38fd1498Szrj#else
201*38fd1498Szrj      template<typename _InputIterator>
202*38fd1498Szrj#endif
203*38fd1498Szrj	vector(_InputIterator __first, _InputIterator __last,
204*38fd1498Szrj	       const _Allocator& __a = _Allocator())
205*38fd1498Szrj	: _Base(__first, __last, __a) { }
206*38fd1498Szrj
207*38fd1498Szrj      /// Construction from a normal-mode vector
208*38fd1498Szrj      vector(const _Base& __x)
209*38fd1498Szrj      : _Base(__x) { }
210*38fd1498Szrj
211*38fd1498Szrj#if __cplusplus >= 201103L
212*38fd1498Szrj      vector(const _Base& __x, const _Allocator& __a)
213*38fd1498Szrj      : _Base(__x, __a) { }
214*38fd1498Szrj
215*38fd1498Szrj      vector(vector&& __x, const _Allocator& __a)
216*38fd1498Szrj      : _Base(std::move(__x), __a) { }
217*38fd1498Szrj
218*38fd1498Szrj      vector(initializer_list<value_type> __l,
219*38fd1498Szrj	     const allocator_type& __a = allocator_type())
220*38fd1498Szrj      : _Base(__l, __a) { }
221*38fd1498Szrj#endif
222*38fd1498Szrj
223*38fd1498Szrj#if __cplusplus < 201103L
224*38fd1498Szrj      vector&
225*38fd1498Szrj      operator=(const vector& __x)
226*38fd1498Szrj      {
227*38fd1498Szrj	this->_M_profile_destruct();
228*38fd1498Szrj	_M_base() = __x;
229*38fd1498Szrj	this->_M_profile_construct();
230*38fd1498Szrj	return *this;
231*38fd1498Szrj      }
232*38fd1498Szrj#else
233*38fd1498Szrj      vector&
234*38fd1498Szrj      operator=(const vector&) = default;
235*38fd1498Szrj
236*38fd1498Szrj      vector&
237*38fd1498Szrj      operator=(vector&&) = default;
238*38fd1498Szrj
239*38fd1498Szrj      vector&
240*38fd1498Szrj      operator=(initializer_list<value_type> __l)
241*38fd1498Szrj      {
242*38fd1498Szrj	this->_M_profile_destruct();
243*38fd1498Szrj	_M_base() = __l;
244*38fd1498Szrj	this->_M_profile_construct();
245*38fd1498Szrj	return *this;
246*38fd1498Szrj      }
247*38fd1498Szrj#endif
248*38fd1498Szrj
249*38fd1498Szrj      // iterators:
250*38fd1498Szrj      iterator
251*38fd1498Szrj      begin() _GLIBCXX_NOEXCEPT
252*38fd1498Szrj      { return iterator(_Base::begin(), this); }
253*38fd1498Szrj
254*38fd1498Szrj      const_iterator
255*38fd1498Szrj      begin() const _GLIBCXX_NOEXCEPT
256*38fd1498Szrj      { return const_iterator(_Base::begin(), this); }
257*38fd1498Szrj
258*38fd1498Szrj      iterator
259*38fd1498Szrj      end() _GLIBCXX_NOEXCEPT
260*38fd1498Szrj      { return iterator(_Base::end(), this); }
261*38fd1498Szrj
262*38fd1498Szrj      const_iterator
263*38fd1498Szrj      end() const _GLIBCXX_NOEXCEPT
264*38fd1498Szrj      { return const_iterator(_Base::end(), this); }
265*38fd1498Szrj
266*38fd1498Szrj      reverse_iterator
267*38fd1498Szrj      rbegin() _GLIBCXX_NOEXCEPT
268*38fd1498Szrj      { return reverse_iterator(end()); }
269*38fd1498Szrj
270*38fd1498Szrj      const_reverse_iterator
271*38fd1498Szrj      rbegin() const _GLIBCXX_NOEXCEPT
272*38fd1498Szrj      { return const_reverse_iterator(end()); }
273*38fd1498Szrj
274*38fd1498Szrj      reverse_iterator
275*38fd1498Szrj      rend() _GLIBCXX_NOEXCEPT
276*38fd1498Szrj      { return reverse_iterator(begin()); }
277*38fd1498Szrj
278*38fd1498Szrj      const_reverse_iterator
279*38fd1498Szrj      rend() const _GLIBCXX_NOEXCEPT
280*38fd1498Szrj      { return const_reverse_iterator(begin()); }
281*38fd1498Szrj
282*38fd1498Szrj#if __cplusplus >= 201103L
283*38fd1498Szrj      const_iterator
284*38fd1498Szrj      cbegin() const noexcept
285*38fd1498Szrj      { return const_iterator(_Base::begin(), this); }
286*38fd1498Szrj
287*38fd1498Szrj      const_iterator
288*38fd1498Szrj      cend() const noexcept
289*38fd1498Szrj      { return const_iterator(_Base::end(), this); }
290*38fd1498Szrj
291*38fd1498Szrj      const_reverse_iterator
292*38fd1498Szrj      crbegin() const noexcept
293*38fd1498Szrj      { return const_reverse_iterator(end()); }
294*38fd1498Szrj
295*38fd1498Szrj      const_reverse_iterator
296*38fd1498Szrj      crend() const noexcept
297*38fd1498Szrj      { return const_reverse_iterator(begin()); }
298*38fd1498Szrj#endif
299*38fd1498Szrj
300*38fd1498Szrj      // 23.2.4.2 capacity:
301*38fd1498Szrj
302*38fd1498Szrj#if __cplusplus >= 201103L
303*38fd1498Szrj      void
304*38fd1498Szrj      resize(size_type __sz)
305*38fd1498Szrj      {
306*38fd1498Szrj	__profcxx_vector2list_invalid_operator(this->_M_vect2list_info);
307*38fd1498Szrj	_M_profile_resize(this->capacity(), __sz);
308*38fd1498Szrj	_Base::resize(__sz);
309*38fd1498Szrj      }
310*38fd1498Szrj
311*38fd1498Szrj      void
312*38fd1498Szrj      resize(size_type __sz, const _Tp& __c)
313*38fd1498Szrj      {
314*38fd1498Szrj	__profcxx_vector2list_invalid_operator(this->_M_vect2list_info);
315*38fd1498Szrj	_M_profile_resize(this->capacity(), __sz);
316*38fd1498Szrj	_Base::resize(__sz, __c);
317*38fd1498Szrj      }
318*38fd1498Szrj#else
319*38fd1498Szrj      void
320*38fd1498Szrj      resize(size_type __sz, _Tp __c = _Tp())
321*38fd1498Szrj      {
322*38fd1498Szrj	__profcxx_vector2list_invalid_operator(this->_M_vect2list_info);
323*38fd1498Szrj	_M_profile_resize(this->capacity(), __sz);
324*38fd1498Szrj	_Base::resize(__sz, __c);
325*38fd1498Szrj      }
326*38fd1498Szrj#endif
327*38fd1498Szrj
328*38fd1498Szrj      // element access:
329*38fd1498Szrj      reference
330*38fd1498Szrj      operator[](size_type __n) _GLIBCXX_NOEXCEPT
331*38fd1498Szrj      {
332*38fd1498Szrj	__profcxx_vector2list_invalid_operator(this->_M_vect2list_info);
333*38fd1498Szrj	return _M_base()[__n];
334*38fd1498Szrj      }
335*38fd1498Szrj      const_reference
336*38fd1498Szrj      operator[](size_type __n) const _GLIBCXX_NOEXCEPT
337*38fd1498Szrj      {
338*38fd1498Szrj	__profcxx_vector2list_invalid_operator(this->_M_vect2list_info);
339*38fd1498Szrj	return _M_base()[__n];
340*38fd1498Szrj      }
341*38fd1498Szrj
342*38fd1498Szrj      // 23.2.4.3 modifiers:
343*38fd1498Szrj      void
344*38fd1498Szrj      push_back(const _Tp& __x)
345*38fd1498Szrj      {
346*38fd1498Szrj	size_type __old_size = this->capacity();
347*38fd1498Szrj	_Base::push_back(__x);
348*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
349*38fd1498Szrj      }
350*38fd1498Szrj
351*38fd1498Szrj#if __cplusplus >= 201103L
352*38fd1498Szrj      void
353*38fd1498Szrj      push_back(_Tp&& __x)
354*38fd1498Szrj      {
355*38fd1498Szrj	size_type __old_size = this->capacity();
356*38fd1498Szrj	_Base::push_back(std::move(__x));
357*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
358*38fd1498Szrj      }
359*38fd1498Szrj
360*38fd1498Szrj#endif
361*38fd1498Szrj
362*38fd1498Szrj      iterator
363*38fd1498Szrj#if __cplusplus >= 201103L
364*38fd1498Szrj      insert(const_iterator __pos, const _Tp& __x)
365*38fd1498Szrj#else
366*38fd1498Szrj      insert(iterator __pos, const _Tp& __x)
367*38fd1498Szrj#endif
368*38fd1498Szrj      {
369*38fd1498Szrj	__profcxx_vector2list_insert(this->_M_vect2list_info,
370*38fd1498Szrj				     __pos.base() - _Base::begin(),
371*38fd1498Szrj				     this->size());
372*38fd1498Szrj	size_type __old_size = this->capacity();
373*38fd1498Szrj	_Base_iterator __res = _Base::insert(__pos.base(), __x);
374*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
375*38fd1498Szrj	return iterator(__res, this);
376*38fd1498Szrj      }
377*38fd1498Szrj
378*38fd1498Szrj#if __cplusplus >= 201103L
379*38fd1498Szrj      iterator
380*38fd1498Szrj      insert(const_iterator __pos, _Tp&& __x)
381*38fd1498Szrj      {
382*38fd1498Szrj	__profcxx_vector2list_insert(this->_M_vect2list_info,
383*38fd1498Szrj				     __pos.base() - _Base::cbegin(),
384*38fd1498Szrj				     this->size());
385*38fd1498Szrj	size_type __old_size = this->capacity();
386*38fd1498Szrj	_Base_iterator __res = _Base::insert(__pos.base(), __x);
387*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
388*38fd1498Szrj	return iterator(__res, this);
389*38fd1498Szrj      }
390*38fd1498Szrj
391*38fd1498Szrj      template<typename... _Args>
392*38fd1498Szrj	iterator
393*38fd1498Szrj	emplace(const_iterator __pos, _Args&&... __args)
394*38fd1498Szrj	{
395*38fd1498Szrj	  _Base_iterator __res = _Base::emplace(__pos.base(),
396*38fd1498Szrj						std::forward<_Args>(__args)...);
397*38fd1498Szrj	  return iterator(__res, this);
398*38fd1498Szrj	}
399*38fd1498Szrj
400*38fd1498Szrj      iterator
401*38fd1498Szrj      insert(const_iterator __pos, initializer_list<value_type> __l)
402*38fd1498Szrj      { return this->insert(__pos, __l.begin(), __l.end()); }
403*38fd1498Szrj#endif
404*38fd1498Szrj
405*38fd1498Szrj      void
406*38fd1498Szrj      swap(vector& __x)
407*38fd1498Szrj#if __cplusplus >= 201103L
408*38fd1498Szrj	noexcept( noexcept(declval<_Base>().swap(__x)) )
409*38fd1498Szrj#endif
410*38fd1498Szrj      {
411*38fd1498Szrj	_Base::swap(__x);
412*38fd1498Szrj	this->_M_swap(__x);
413*38fd1498Szrj      }
414*38fd1498Szrj
415*38fd1498Szrj#if __cplusplus >= 201103L
416*38fd1498Szrj      iterator
417*38fd1498Szrj      insert(const_iterator __pos, size_type __n, const _Tp& __x)
418*38fd1498Szrj      {
419*38fd1498Szrj	__profcxx_vector2list_insert(this->_M_vect2list_info,
420*38fd1498Szrj				     __pos.base() - _Base::cbegin(),
421*38fd1498Szrj				     this->size());
422*38fd1498Szrj	size_type __old_size = this->capacity();
423*38fd1498Szrj	_Base_iterator __res = _Base::insert(__pos, __n, __x);
424*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
425*38fd1498Szrj	return iterator(__res, this);
426*38fd1498Szrj      }
427*38fd1498Szrj#else
428*38fd1498Szrj      void
429*38fd1498Szrj      insert(iterator __pos, size_type __n, const _Tp& __x)
430*38fd1498Szrj      {
431*38fd1498Szrj	__profcxx_vector2list_insert(this->_M_vect2list_info,
432*38fd1498Szrj				     __pos.base() - _Base::begin(),
433*38fd1498Szrj				     this->size());
434*38fd1498Szrj	size_type __old_size = this->capacity();
435*38fd1498Szrj	_Base::insert(__pos, __n, __x);
436*38fd1498Szrj	_M_profile_resize(__old_size, this->capacity());
437*38fd1498Szrj      }
438*38fd1498Szrj#endif
439*38fd1498Szrj
440*38fd1498Szrj#if __cplusplus >= 201103L
441*38fd1498Szrj      template<typename _InputIterator,
442*38fd1498Szrj	       typename = std::_RequireInputIter<_InputIterator>>
443*38fd1498Szrj	iterator
444*38fd1498Szrj	insert(const_iterator __pos,
445*38fd1498Szrj	       _InputIterator __first, _InputIterator __last)
446*38fd1498Szrj	{
447*38fd1498Szrj	  __profcxx_vector2list_insert(this->_M_vect2list_info,
448*38fd1498Szrj				       __pos.base() - _Base::cbegin(),
449*38fd1498Szrj				       this->size());
450*38fd1498Szrj	  size_type __old_size = this->capacity();
451*38fd1498Szrj	  _Base_iterator __res = _Base::insert(__pos, __first, __last);
452*38fd1498Szrj	  _M_profile_resize(__old_size, this->capacity());
453*38fd1498Szrj	  return iterator(__res, this);
454*38fd1498Szrj	}
455*38fd1498Szrj#else
456*38fd1498Szrj      template<typename _InputIterator>
457*38fd1498Szrj	void
458*38fd1498Szrj	insert(iterator __pos,
459*38fd1498Szrj	       _InputIterator __first, _InputIterator __last)
460*38fd1498Szrj	{
461*38fd1498Szrj	  __profcxx_vector2list_insert(this->_M_vect2list_info,
462*38fd1498Szrj				       __pos.base() - _Base::begin(),
463*38fd1498Szrj				       this->size());
464*38fd1498Szrj	  size_type __old_size = this->capacity();
465*38fd1498Szrj	  _Base::insert(__pos, __first, __last);
466*38fd1498Szrj	  _M_profile_resize(__old_size, this->capacity());
467*38fd1498Szrj	}
468*38fd1498Szrj#endif
469*38fd1498Szrj
470*38fd1498Szrj      iterator
471*38fd1498Szrj#if __cplusplus >= 201103L
472*38fd1498Szrj      erase(const_iterator __pos)
473*38fd1498Szrj#else
474*38fd1498Szrj      erase(iterator __pos)
475*38fd1498Szrj#endif
476*38fd1498Szrj      { return iterator(_Base::erase(__pos.base()), this); }
477*38fd1498Szrj
478*38fd1498Szrj      iterator
479*38fd1498Szrj#if __cplusplus >= 201103L
480*38fd1498Szrj      erase(const_iterator __first, const_iterator __last)
481*38fd1498Szrj#else
482*38fd1498Szrj      erase(iterator __first, iterator __last)
483*38fd1498Szrj#endif
484*38fd1498Szrj      { return iterator(_Base::erase(__first.base(), __last.base()), this); }
485*38fd1498Szrj
486*38fd1498Szrj      void
487*38fd1498Szrj      clear() _GLIBCXX_NOEXCEPT
488*38fd1498Szrj      {
489*38fd1498Szrj	this->_M_profile_destruct();
490*38fd1498Szrj	_Base::clear();
491*38fd1498Szrj	this->_M_profile_construct();
492*38fd1498Szrj      }
493*38fd1498Szrj
494*38fd1498Szrj      inline void
495*38fd1498Szrj      _M_profile_iterate(int __rewind = 0) const
496*38fd1498Szrj      { __profcxx_vector2list_iterate(this->_M_vect2list_info, __rewind); }
497*38fd1498Szrj
498*38fd1498Szrj    private:
499*38fd1498Szrj      void _M_profile_resize(size_type __old_size, size_type __new_size)
500*38fd1498Szrj      {
501*38fd1498Szrj	if (__old_size < __new_size)
502*38fd1498Szrj	  {
503*38fd1498Szrj	    __profcxx_vector_size_resize(this->_M_size_info,
504*38fd1498Szrj					 this->size(), __new_size);
505*38fd1498Szrj	    __profcxx_vector2list_resize(this->_M_vect2list_info,
506*38fd1498Szrj					 this->size(), __new_size);
507*38fd1498Szrj	  }
508*38fd1498Szrj      }
509*38fd1498Szrj    };
510*38fd1498Szrj
511*38fd1498Szrj  template<typename _Tp, typename _Alloc>
512*38fd1498Szrj    inline bool
513*38fd1498Szrj    operator==(const vector<_Tp, _Alloc>& __lhs,
514*38fd1498Szrj	       const vector<_Tp, _Alloc>& __rhs)
515*38fd1498Szrj    { return __lhs._M_base() == __rhs._M_base(); }
516*38fd1498Szrj
517*38fd1498Szrj  template<typename _Tp, typename _Alloc>
518*38fd1498Szrj    inline bool
519*38fd1498Szrj    operator!=(const vector<_Tp, _Alloc>& __lhs,
520*38fd1498Szrj	       const vector<_Tp, _Alloc>& __rhs)
521*38fd1498Szrj    { return __lhs._M_base() != __rhs._M_base(); }
522*38fd1498Szrj
523*38fd1498Szrj  template<typename _Tp, typename _Alloc>
524*38fd1498Szrj    inline bool
525*38fd1498Szrj    operator<(const vector<_Tp, _Alloc>& __lhs,
526*38fd1498Szrj	      const vector<_Tp, _Alloc>& __rhs)
527*38fd1498Szrj    { return __lhs._M_base() < __rhs._M_base(); }
528*38fd1498Szrj
529*38fd1498Szrj  template<typename _Tp, typename _Alloc>
530*38fd1498Szrj    inline bool
531*38fd1498Szrj    operator<=(const vector<_Tp, _Alloc>& __lhs,
532*38fd1498Szrj	       const vector<_Tp, _Alloc>& __rhs)
533*38fd1498Szrj    { return __lhs._M_base() <= __rhs._M_base(); }
534*38fd1498Szrj
535*38fd1498Szrj  template<typename _Tp, typename _Alloc>
536*38fd1498Szrj    inline bool
537*38fd1498Szrj    operator>=(const vector<_Tp, _Alloc>& __lhs,
538*38fd1498Szrj	       const vector<_Tp, _Alloc>& __rhs)
539*38fd1498Szrj    { return __lhs._M_base() >= __rhs._M_base(); }
540*38fd1498Szrj
541*38fd1498Szrj  template<typename _Tp, typename _Alloc>
542*38fd1498Szrj    inline bool
543*38fd1498Szrj    operator>(const vector<_Tp, _Alloc>& __lhs,
544*38fd1498Szrj	      const vector<_Tp, _Alloc>& __rhs)
545*38fd1498Szrj    { return __lhs._M_base() > __rhs._M_base(); }
546*38fd1498Szrj
547*38fd1498Szrj  template<typename _Tp, typename _Alloc>
548*38fd1498Szrj    inline void
549*38fd1498Szrj    swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
550*38fd1498Szrj    _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
551*38fd1498Szrj    { __lhs.swap(__rhs); }
552*38fd1498Szrj
553*38fd1498Szrj} // namespace __profile
554*38fd1498Szrj
555*38fd1498Szrj#if __cplusplus >= 201103L
556*38fd1498Szrj  // DR 1182.
557*38fd1498Szrj  /// std::hash specialization for vector<bool>.
558*38fd1498Szrj  template<typename _Alloc>
559*38fd1498Szrj    struct hash<__profile::vector<bool, _Alloc>>
560*38fd1498Szrj    : public __hash_base<size_t, __profile::vector<bool, _Alloc>>
561*38fd1498Szrj    {
562*38fd1498Szrj      size_t
563*38fd1498Szrj      operator()(const __profile::vector<bool, _Alloc>& __b) const noexcept
564*38fd1498Szrj      {
565*38fd1498Szrj	return std::hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>()(__b._M_base());
566*38fd1498Szrj      }
567*38fd1498Szrj    };
568*38fd1498Szrj#endif
569*38fd1498Szrj
570*38fd1498Szrj} // namespace std
571*38fd1498Szrj
572*38fd1498Szrj#endif
573