57 #define _STL_DEQUE_H 1
62 #if __cplusplus >= 201103L
63 #include <initializer_list>
66 namespace std _GLIBCXX_VISIBILITY(default)
68 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
84 #ifndef _GLIBCXX_DEQUE_BUF_SIZE
85 #define _GLIBCXX_DEQUE_BUF_SIZE 512
89 __deque_buf_size(
size_t __size)
105 template<
typename _Tp,
typename _Ref,
typename _Ptr>
111 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
112 {
return __deque_buf_size(
sizeof(_Tp)); }
115 typedef _Tp value_type;
116 typedef _Ptr pointer;
117 typedef _Ref reference;
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
120 typedef _Tp** _Map_pointer;
126 _Map_pointer _M_node;
129 : _M_cur(__x), _M_first(*__y),
130 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
133 : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { }
136 : _M_cur(__x._M_cur), _M_first(__x._M_first),
137 _M_last(__x._M_last), _M_node(__x._M_node) { }
140 _M_const_cast()
const _GLIBCXX_NOEXCEPT
141 {
return iterator(_M_cur, _M_node); }
144 operator*()
const _GLIBCXX_NOEXCEPT
148 operator->()
const _GLIBCXX_NOEXCEPT
152 operator++() _GLIBCXX_NOEXCEPT
155 if (_M_cur == _M_last)
164 operator++(
int) _GLIBCXX_NOEXCEPT
172 operator--() _GLIBCXX_NOEXCEPT
174 if (_M_cur == _M_first)
184 operator--(
int) _GLIBCXX_NOEXCEPT
192 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
194 const difference_type __offset = __n + (_M_cur - _M_first);
195 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
199 const difference_type __node_offset =
200 __offset > 0 ? __offset / difference_type(_S_buffer_size())
201 : -difference_type((-__offset - 1)
202 / _S_buffer_size()) - 1;
204 _M_cur = _M_first + (__offset - __node_offset
205 * difference_type(_S_buffer_size()));
211 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
218 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
219 {
return *
this += -__n; }
222 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
229 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
230 {
return *(*
this + __n); }
240 _M_node = __new_node;
241 _M_first = *__new_node;
242 _M_last = _M_first + difference_type(_S_buffer_size());
249 template<
typename _Tp,
typename _Ref,
typename _Ptr>
251 operator==(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
252 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
253 {
return __x._M_cur == __y._M_cur; }
255 template<
typename _Tp,
typename _RefL,
typename _PtrL,
256 typename _RefR,
typename _PtrR>
258 operator==(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
259 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
260 {
return __x._M_cur == __y._M_cur; }
262 template<
typename _Tp,
typename _Ref,
typename _Ptr>
264 operator!=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
265 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
266 {
return !(__x == __y); }
268 template<
typename _Tp,
typename _RefL,
typename _PtrL,
269 typename _RefR,
typename _PtrR>
271 operator!=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
272 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
273 {
return !(__x == __y); }
275 template<
typename _Tp,
typename _Ref,
typename _Ptr>
277 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
278 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
279 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
280 : (__x._M_node < __y._M_node); }
282 template<
typename _Tp,
typename _RefL,
typename _PtrL,
283 typename _RefR,
typename _PtrR>
285 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
286 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
287 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
288 : (__x._M_node < __y._M_node); }
290 template<
typename _Tp,
typename _Ref,
typename _Ptr>
292 operator>(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
293 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
294 {
return __y < __x; }
296 template<
typename _Tp,
typename _RefL,
typename _PtrL,
297 typename _RefR,
typename _PtrR>
299 operator>(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
300 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
301 {
return __y < __x; }
303 template<
typename _Tp,
typename _Ref,
typename _Ptr>
305 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
306 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
307 {
return !(__y < __x); }
309 template<
typename _Tp,
typename _RefL,
typename _PtrL,
310 typename _RefR,
typename _PtrR>
312 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
313 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
314 {
return !(__y < __x); }
316 template<
typename _Tp,
typename _Ref,
typename _Ptr>
318 operator>=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
319 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
320 {
return !(__x < __y); }
322 template<
typename _Tp,
typename _RefL,
typename _PtrL,
323 typename _RefR,
typename _PtrR>
325 operator>=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
326 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
327 {
return !(__x < __y); }
333 template<
typename _Tp,
typename _Ref,
typename _Ptr>
334 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
335 operator-(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
336 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
338 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
339 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
340 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
341 + (__y._M_last - __y._M_cur);
344 template<
typename _Tp,
typename _RefL,
typename _PtrL,
345 typename _RefR,
typename _PtrR>
346 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
347 operator-(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
348 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
350 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
351 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
352 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
353 + (__y._M_last - __y._M_cur);
356 template<
typename _Tp,
typename _Ref,
typename _Ptr>
357 inline _Deque_iterator<_Tp, _Ref, _Ptr>
358 operator+(ptrdiff_t __n,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
360 {
return __x + __n; }
362 template<
typename _Tp>
364 fill(
const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
365 const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
const _Tp&);
367 template<
typename _Tp>
368 _Deque_iterator<_Tp, _Tp&, _Tp*>
369 copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
370 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
371 _Deque_iterator<_Tp, _Tp&, _Tp*>);
373 template<
typename _Tp>
374 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
375 copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
376 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
377 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
378 {
return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
379 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
382 template<
typename _Tp>
383 _Deque_iterator<_Tp, _Tp&, _Tp*>
384 copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
385 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
386 _Deque_iterator<_Tp, _Tp&, _Tp*>);
388 template<
typename _Tp>
389 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
390 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
391 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
392 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
393 {
return std::copy_backward(_Deque_iterator<_Tp,
394 const _Tp&,
const _Tp*>(__first),
396 const _Tp&,
const _Tp*>(__last),
399 #if __cplusplus >= 201103L
400 template<
typename _Tp>
401 _Deque_iterator<_Tp, _Tp&, _Tp*>
402 move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
403 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
404 _Deque_iterator<_Tp, _Tp&, _Tp*>);
406 template<
typename _Tp>
407 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
408 move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
409 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
410 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
411 {
return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
412 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
415 template<
typename _Tp>
416 _Deque_iterator<_Tp, _Tp&, _Tp*>
418 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
419 _Deque_iterator<_Tp, _Tp&, _Tp*>);
421 template<
typename _Tp>
422 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
424 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
425 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
427 const _Tp&,
const _Tp*>(__first),
429 const _Tp&,
const _Tp*>(__last),
443 template<
typename _Tp,
typename _Alloc>
447 typedef _Alloc allocator_type;
450 get_allocator()
const _GLIBCXX_NOEXCEPT
451 {
return allocator_type(_M_get_Tp_allocator()); }
464 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
472 #if __cplusplus >= 201103L
474 : _M_impl(
std::move(__x._M_get_Tp_allocator()))
477 if (__x._M_impl._M_map)
479 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
480 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
481 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
482 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
490 typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
492 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
498 :
public _Tp_alloc_type
506 : _Tp_alloc_type(), _M_map(0), _M_map_size(0),
507 _M_start(), _M_finish()
510 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
511 : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
512 _M_start(), _M_finish()
515 #if __cplusplus >= 201103L
516 _Deque_impl(_Tp_alloc_type&& __a) _GLIBCXX_NOEXCEPT
517 : _Tp_alloc_type(
std::move(__a)), _M_map(0), _M_map_size(0),
518 _M_start(), _M_finish()
524 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
525 {
return *
static_cast<_Tp_alloc_type*
>(&this->_M_impl); }
527 const _Tp_alloc_type&
528 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
529 {
return *
static_cast<const _Tp_alloc_type*
>(&this->_M_impl); }
532 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
533 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
538 return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(
sizeof(_Tp)));
542 _M_deallocate_node(_Tp* __p) _GLIBCXX_NOEXCEPT
544 _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(
sizeof(_Tp)));
548 _M_allocate_map(
size_t __n)
549 {
return _M_get_map_allocator().allocate(__n); }
552 _M_deallocate_map(_Tp** __p,
size_t __n) _GLIBCXX_NOEXCEPT
553 { _M_get_map_allocator().deallocate(__p, __n); }
557 void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
558 void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish) _GLIBCXX_NOEXCEPT;
559 enum { _S_initial_map_size = 8 };
564 template<
typename _Tp,
typename _Alloc>
568 if (this->_M_impl._M_map)
570 _M_destroy_nodes(this->_M_impl._M_start._M_node,
571 this->_M_impl._M_finish._M_node + 1);
572 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
584 template<
typename _Tp,
typename _Alloc>
589 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
592 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
593 size_t(__num_nodes + 2));
594 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
601 _Tp** __nstart = (this->_M_impl._M_map
602 + (this->_M_impl._M_map_size - __num_nodes) / 2);
603 _Tp** __nfinish = __nstart + __num_nodes;
606 { _M_create_nodes(__nstart, __nfinish); }
609 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
610 this->_M_impl._M_map = 0;
611 this->_M_impl._M_map_size = 0;
612 __throw_exception_again;
615 this->_M_impl._M_start._M_set_node(__nstart);
616 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
617 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
618 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
620 % __deque_buf_size(
sizeof(_Tp)));
623 template<
typename _Tp,
typename _Alloc>
631 for (__cur = __nstart; __cur < __nfinish; ++__cur)
632 *__cur = this->_M_allocate_node();
636 _M_destroy_nodes(__nstart, __cur);
637 __throw_exception_again;
641 template<
typename _Tp,
typename _Alloc>
643 _Deque_base<_Tp, _Alloc>::
644 _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish) _GLIBCXX_NOEXCEPT
646 for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
647 _M_deallocate_node(*__n);
734 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
738 typedef typename _Alloc::value_type _Alloc_value_type;
739 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
740 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
743 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
746 typedef _Tp value_type;
747 typedef typename _Tp_alloc_type::pointer pointer;
748 typedef typename _Tp_alloc_type::const_pointer const_pointer;
749 typedef typename _Tp_alloc_type::reference reference;
750 typedef typename _Tp_alloc_type::const_reference const_reference;
755 typedef size_t size_type;
756 typedef ptrdiff_t difference_type;
757 typedef _Alloc allocator_type;
760 typedef pointer* _Map_pointer;
762 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
763 {
return __deque_buf_size(
sizeof(_Tp)); }
767 using _Base::_M_create_nodes;
768 using _Base::_M_destroy_nodes;
769 using _Base::_M_allocate_node;
770 using _Base::_M_deallocate_node;
771 using _Base::_M_allocate_map;
772 using _Base::_M_deallocate_map;
773 using _Base::_M_get_Tp_allocator;
779 using _Base::_M_impl;
798 #if __cplusplus >= 201103L
809 { _M_default_initialize(); }
819 deque(size_type __n,
const value_type& __value,
820 const allocator_type& __a = allocator_type())
833 deque(size_type __n,
const value_type& __value = value_type(),
834 const allocator_type& __a = allocator_type())
847 : _Base(__x._M_get_Tp_allocator(), __x.
size())
848 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
849 this->_M_impl._M_start,
850 _M_get_Tp_allocator()); }
852 #if __cplusplus >= 201103L
874 deque(initializer_list<value_type> __l,
875 const allocator_type& __a = allocator_type())
898 #if __cplusplus >= 201103L
899 template<
typename _InputIterator,
900 typename = std::_RequireInputIter<_InputIterator>>
901 deque(_InputIterator __first, _InputIterator __last,
902 const allocator_type& __a = allocator_type())
904 { _M_initialize_dispatch(__first, __last, __false_type()); }
906 template<
typename _InputIterator>
907 deque(_InputIterator __first, _InputIterator __last,
908 const allocator_type& __a = allocator_type())
912 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
913 _M_initialize_dispatch(__first, __last, _Integral());
923 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
935 #if __cplusplus >= 201103L
967 this->
assign(__l.begin(), __l.end());
983 assign(size_type __n,
const value_type& __val)
984 { _M_fill_assign(__n, __val); }
998 #if __cplusplus >= 201103L
999 template<
typename _InputIterator,
1000 typename = std::_RequireInputIter<_InputIterator>>
1002 assign(_InputIterator __first, _InputIterator __last)
1003 { _M_assign_dispatch(__first, __last, __false_type()); }
1005 template<
typename _InputIterator>
1007 assign(_InputIterator __first, _InputIterator __last)
1009 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1010 _M_assign_dispatch(__first, __last, _Integral());
1014 #if __cplusplus >= 201103L
1028 { this->
assign(__l.begin(), __l.end()); }
1034 {
return _Base::get_allocator(); }
1043 {
return this->_M_impl._M_start; }
1051 {
return this->_M_impl._M_start; }
1060 {
return this->_M_impl._M_finish; }
1069 {
return this->_M_impl._M_finish; }
1078 {
return reverse_iterator(this->_M_impl._M_finish); }
1085 const_reverse_iterator
1087 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1096 {
return reverse_iterator(this->_M_impl._M_start); }
1103 const_reverse_iterator
1105 {
return const_reverse_iterator(this->_M_impl._M_start); }
1107 #if __cplusplus >= 201103L
1114 {
return this->_M_impl._M_start; }
1123 {
return this->_M_impl._M_finish; }
1130 const_reverse_iterator
1132 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1139 const_reverse_iterator
1141 {
return const_reverse_iterator(this->_M_impl._M_start); }
1148 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1153 {
return _M_get_Tp_allocator().max_size(); }
1155 #if __cplusplus >= 201103L
1168 const size_type __len =
size();
1169 if (__new_size > __len)
1170 _M_default_append(__new_size - __len);
1171 else if (__new_size < __len)
1172 _M_erase_at_end(this->_M_impl._M_start
1173 + difference_type(__new_size));
1188 resize(size_type __new_size,
const value_type& __x)
1190 const size_type __len =
size();
1191 if (__new_size > __len)
1192 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1193 else if (__new_size < __len)
1194 _M_erase_at_end(this->_M_impl._M_start
1195 + difference_type(__new_size));
1210 resize(size_type __new_size, value_type __x = value_type())
1212 const size_type __len =
size();
1213 if (__new_size > __len)
1214 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1215 else if (__new_size < __len)
1216 _M_erase_at_end(this->_M_impl._M_start
1217 + difference_type(__new_size));
1221 #if __cplusplus >= 201103L
1225 { _M_shrink_to_fit(); }
1234 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1250 {
return this->_M_impl._M_start[difference_type(__n)]; }
1265 {
return this->_M_impl._M_start[difference_type(__n)]; }
1272 if (__n >= this->
size())
1273 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n "
1274 "(which is %zu)>= this->size() "
1295 return (*
this)[__n];
1313 return (*
this)[__n];
1322 {
return *
begin(); }
1330 {
return *
begin(); }
1339 iterator __tmp =
end();
1351 const_iterator __tmp =
end();
1369 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1371 this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x);
1372 --this->_M_impl._M_start._M_cur;
1378 #if __cplusplus >= 201103L
1383 template<
typename... _Args>
1385 emplace_front(_Args&&... __args);
1400 if (this->_M_impl._M_finish._M_cur
1401 != this->_M_impl._M_finish._M_last - 1)
1403 this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
1404 ++this->_M_impl._M_finish._M_cur;
1410 #if __cplusplus >= 201103L
1415 template<
typename... _Args>
1417 emplace_back(_Args&&... __args);
1431 if (this->_M_impl._M_start._M_cur
1432 != this->_M_impl._M_start._M_last - 1)
1434 this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
1435 ++this->_M_impl._M_start._M_cur;
1452 if (this->_M_impl._M_finish._M_cur
1453 != this->_M_impl._M_finish._M_first)
1455 --this->_M_impl._M_finish._M_cur;
1456 this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
1462 #if __cplusplus >= 201103L
1472 template<
typename... _Args>
1474 emplace(const_iterator __position, _Args&&... __args);
1486 insert(const_iterator __position,
const value_type& __x);
1498 insert(iterator __position,
const value_type& __x);
1501 #if __cplusplus >= 201103L
1512 insert(const_iterator __position, value_type&& __x)
1525 insert(const_iterator __p, initializer_list<value_type> __l)
1526 {
return this->
insert(__p, __l.begin(), __l.end()); }
1529 #if __cplusplus >= 201103L
1541 insert(const_iterator __position, size_type __n,
const value_type& __x)
1543 difference_type __offset = __position -
cbegin();
1544 _M_fill_insert(__position._M_const_cast(), __n, __x);
1545 return begin() + __offset;
1558 insert(iterator __position, size_type __n,
const value_type& __x)
1559 { _M_fill_insert(__position, __n, __x); }
1562 #if __cplusplus >= 201103L
1574 template<
typename _InputIterator,
1575 typename = std::_RequireInputIter<_InputIterator>>
1577 insert(const_iterator __position, _InputIterator __first,
1578 _InputIterator __last)
1580 difference_type __offset = __position -
cbegin();
1581 _M_insert_dispatch(__position._M_const_cast(),
1582 __first, __last, __false_type());
1583 return begin() + __offset;
1596 template<
typename _InputIterator>
1598 insert(iterator __position, _InputIterator __first,
1599 _InputIterator __last)
1602 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1603 _M_insert_dispatch(__position, __first, __last, _Integral());
1621 #if __cplusplus >= 201103L
1624 erase(iterator __position)
1626 {
return _M_erase(__position._M_const_cast()); }
1645 #if __cplusplus >= 201103L
1646 erase(const_iterator __first, const_iterator __last)
1648 erase(iterator __first, iterator __last)
1650 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1664 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
1665 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
1666 std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
1667 std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
1671 std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
1672 __x._M_get_Tp_allocator());
1683 { _M_erase_at_end(
begin()); }
1692 template<
typename _Integer>
1694 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1701 template<
typename _InputIterator>
1703 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1706 typedef typename std::iterator_traits<_InputIterator>::
1707 iterator_category _IterCategory;
1723 template<
typename _InputIterator>
1729 template<
typename _ForwardIterator>
1748 #if __cplusplus >= 201103L
1751 _M_default_initialize();
1761 template<
typename _Integer>
1763 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1764 { _M_fill_assign(__n, __val); }
1767 template<
typename _InputIterator>
1769 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1772 typedef typename std::iterator_traits<_InputIterator>::
1773 iterator_category _IterCategory;
1774 _M_assign_aux(__first, __last, _IterCategory());
1778 template<
typename _InputIterator>
1780 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1784 template<
typename _ForwardIterator>
1786 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1792 _ForwardIterator __mid = __first;
1794 std::copy(__first, __mid,
begin());
1798 _M_erase_at_end(std::copy(__first, __last,
begin()));
1804 _M_fill_assign(size_type __n,
const value_type& __val)
1813 _M_erase_at_end(
begin() + difference_type(__n));
1820 #if __cplusplus < 201103L
1825 template<
typename... _Args>
1828 template<
typename... _Args>
1844 template<
typename _Integer>
1846 _M_insert_dispatch(iterator __pos,
1847 _Integer __n, _Integer __x, __true_type)
1848 { _M_fill_insert(__pos, __n, __x); }
1851 template<
typename _InputIterator>
1853 _M_insert_dispatch(iterator __pos,
1854 _InputIterator __first, _InputIterator __last,
1857 typedef typename std::iterator_traits<_InputIterator>::
1858 iterator_category _IterCategory;
1859 _M_range_insert_aux(__pos, __first, __last, _IterCategory());
1863 template<
typename _InputIterator>
1865 _M_range_insert_aux(iterator __pos, _InputIterator __first,
1869 template<
typename _ForwardIterator>
1871 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
1878 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1881 #if __cplusplus < 201103L
1883 _M_insert_aux(iterator __pos,
const value_type& __x);
1885 template<
typename... _Args>
1887 _M_insert_aux(iterator __pos, _Args&&... __args);
1892 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
1895 template<
typename _ForwardIterator>
1897 _M_insert_aux(iterator __pos,
1898 _ForwardIterator __first, _ForwardIterator __last,
1905 _M_destroy_data_aux(iterator __first, iterator __last);
1909 template<
typename _Alloc1>
1911 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
1912 { _M_destroy_data_aux(__first, __last); }
1915 _M_destroy_data(iterator __first, iterator __last,
1918 if (!__has_trivial_destructor(value_type))
1919 _M_destroy_data_aux(__first, __last);
1924 _M_erase_at_begin(iterator __pos)
1926 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
1927 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
1928 this->_M_impl._M_start = __pos;
1934 _M_erase_at_end(iterator __pos)
1936 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
1937 _M_destroy_nodes(__pos._M_node + 1,
1938 this->_M_impl._M_finish._M_node + 1);
1939 this->_M_impl._M_finish = __pos;
1943 _M_erase(iterator __pos);
1946 _M_erase(iterator __first, iterator __last);
1948 #if __cplusplus >= 201103L
1951 _M_default_append(size_type __n);
1962 const size_type __vacancies = this->_M_impl._M_start._M_cur
1963 - this->_M_impl._M_start._M_first;
1964 if (__n > __vacancies)
1966 return this->_M_impl._M_start - difference_type(__n);
1972 const size_type __vacancies = (this->_M_impl._M_finish._M_last
1973 - this->_M_impl._M_finish._M_cur) - 1;
1974 if (__n > __vacancies)
1976 return this->_M_impl._M_finish + difference_type(__n);
1998 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
1999 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2006 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2007 - this->_M_impl._M_map))
2027 template<
typename _Tp,
typename _Alloc>
2045 template<
typename _Tp,
typename _Alloc>
2047 operator<(const deque<_Tp, _Alloc>& __x,
2050 __y.begin(), __y.end()); }
2053 template<
typename _Tp,
typename _Alloc>
2057 {
return !(__x == __y); }
2060 template<
typename _Tp,
typename _Alloc>
2064 {
return __y < __x; }
2067 template<
typename _Tp,
typename _Alloc>
2069 operator<=(const deque<_Tp, _Alloc>& __x,
2071 {
return !(__y < __x); }
2074 template<
typename _Tp,
typename _Alloc>
2078 {
return !(__x < __y); }
2081 template<
typename _Tp,
typename _Alloc>
2086 #undef _GLIBCXX_DEQUE_BUF_SIZE
2088 _GLIBCXX_END_NAMESPACE_CONTAINER
const_reverse_iterator crbegin() const noexcept
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void pop_front() noexcept
Removes first element.
const_iterator end() const noexcept
const_iterator cbegin() const noexcept
const_reverse_iterator rend() const noexcept
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
void _M_push_front_aux(_Args &&...__args)
Helper functions for push_* and pop_*.
const_reference front() const noexcept
void push_front(const value_type &__x)
Add data to the front of the deque.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into deque before specified iterator.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
deque(size_type __n)
Creates a deque with default constructed elements.
void _M_push_back_aux(_Args &&...__args)
Helper functions for push_* and pop_*.
Forward iterators support a superset of input iterator operations.
reference back() noexcept
const_reference back() const noexcept
void _M_new_elements_at_back(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
void _M_range_initialize(_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
Fills the deque with whatever is in [first,last).
const_iterator cend() const noexcept
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
void _M_pop_back_aux()
Helper functions for push_* and pop_*.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
void _M_range_check(size_type __n) const
Safety check used only from at().
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
reference at(size_type __n)
Provides access to the data contained in the deque.
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
const_iterator begin() const noexcept
reverse_iterator rbegin() noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
void push_back(const value_type &__x)
Add data to the end of the deque.
deque(const deque &__x)
Deque copy constructor.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
reference front() noexcept
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
bool empty() const noexcept
ISO C++ entities toplevel namespace is std.
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
deque()
Creates a deque with no elements.
void _M_set_node(_Map_pointer __new_node) noexcept
size_type max_size() const noexcept
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
const_reverse_iterator crend() const noexcept
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
The standard allocator, as per [20.4].
iterator begin() noexcept
iterator erase(const_iterator __position)
Remove element at given position.
void pop_back() noexcept
Removes last element.
iterator emplace(const_iterator __position, _Args &&...__args)
Inserts an object in deque before specified iterator.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
deque & operator=(deque &&__x) noexcept
Deque move assignment operator.
void _M_initialize_map(size_t)
Layout storage.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
const_reverse_iterator rbegin() const noexcept
void swap(deque &__x) noexcept
Swaps data with another deque.
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
void shrink_to_fit() noexcept
size_type size() const noexcept
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
deque & operator=(const deque &__x)
Deque assignment operator.
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
_BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
Random-access iterators support a superset of bidirectional iterator operations.
deque(deque &&__x)
Deque move constructor.
void _M_new_elements_at_front(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
void _M_pop_front_aux()
Helper functions for push_* and pop_*.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
Memory-handling helpers for the major map.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
deque(const allocator_type &__a)
Creates a deque with no elements.
void _M_fill_initialize(const value_type &__value)
Fills the deque with copies of value.
reverse_iterator rend() noexcept