57 #define _STL_DEQUE_H 1 62 #if __cplusplus >= 201103L 68 namespace std _GLIBCXX_VISIBILITY(default)
70 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
86 #ifndef _GLIBCXX_DEQUE_BUF_SIZE 87 #define _GLIBCXX_DEQUE_BUF_SIZE 512 90 _GLIBCXX_CONSTEXPR
inline size_t 91 __deque_buf_size(
size_t __size)
107 template<
typename _Tp,
typename _Ref,
typename _Ptr>
110 #if __cplusplus < 201103L 113 typedef _Tp* _Elt_pointer;
114 typedef _Tp** _Map_pointer;
117 template<
typename _Up>
119 template<
typename _CvTp>
124 typedef __ptr_to<_Tp> _Elt_pointer;
125 typedef __ptr_to<_Elt_pointer> _Map_pointer;
128 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
129 {
return __deque_buf_size(
sizeof(_Tp)); }
132 typedef _Tp value_type;
133 typedef _Ptr pointer;
134 typedef _Ref reference;
135 typedef size_t size_type;
136 typedef ptrdiff_t difference_type;
140 _Elt_pointer _M_first;
141 _Elt_pointer _M_last;
142 _Map_pointer _M_node;
145 : _M_cur(__x), _M_first(*__y),
146 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
149 : _M_cur(), _M_first(), _M_last(), _M_node() { }
152 : _M_cur(__x._M_cur), _M_first(__x._M_first),
153 _M_last(__x._M_last), _M_node(__x._M_node) { }
156 _M_const_cast()
const _GLIBCXX_NOEXCEPT
157 {
return iterator(_M_cur, _M_node); }
160 operator*()
const _GLIBCXX_NOEXCEPT
164 operator->()
const _GLIBCXX_NOEXCEPT
168 operator++() _GLIBCXX_NOEXCEPT
171 if (_M_cur == _M_last)
180 operator++(
int) _GLIBCXX_NOEXCEPT
188 operator--() _GLIBCXX_NOEXCEPT
190 if (_M_cur == _M_first)
200 operator--(
int) _GLIBCXX_NOEXCEPT
208 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
210 const difference_type __offset = __n + (_M_cur - _M_first);
211 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
215 const difference_type __node_offset =
216 __offset > 0 ? __offset / difference_type(_S_buffer_size())
217 : -difference_type((-__offset - 1)
218 / _S_buffer_size()) - 1;
220 _M_cur = _M_first + (__offset - __node_offset
221 * difference_type(_S_buffer_size()));
227 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
234 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
235 {
return *
this += -__n; }
238 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
245 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
246 {
return *(*
this + __n); }
256 _M_node = __new_node;
257 _M_first = *__new_node;
258 _M_last = _M_first + difference_type(_S_buffer_size());
265 template<
typename _Tp,
typename _Ref,
typename _Ptr>
269 {
return __x._M_cur == __y._M_cur; }
271 template<
typename _Tp,
typename _RefL,
typename _PtrL,
272 typename _RefR,
typename _PtrR>
276 {
return __x._M_cur == __y._M_cur; }
278 template<
typename _Tp,
typename _Ref,
typename _Ptr>
282 {
return !(__x == __y); }
284 template<
typename _Tp,
typename _RefL,
typename _PtrL,
285 typename _RefR,
typename _PtrR>
289 {
return !(__x == __y); }
291 template<
typename _Tp,
typename _Ref,
typename _Ptr>
293 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
295 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
296 : (__x._M_node < __y._M_node); }
298 template<
typename _Tp,
typename _RefL,
typename _PtrL,
299 typename _RefR,
typename _PtrR>
301 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
303 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
304 : (__x._M_node < __y._M_node); }
306 template<
typename _Tp,
typename _Ref,
typename _Ptr>
310 {
return __y < __x; }
312 template<
typename _Tp,
typename _RefL,
typename _PtrL,
313 typename _RefR,
typename _PtrR>
317 {
return __y < __x; }
319 template<
typename _Tp,
typename _Ref,
typename _Ptr>
321 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
323 {
return !(__y < __x); }
325 template<
typename _Tp,
typename _RefL,
typename _PtrL,
326 typename _RefR,
typename _PtrR>
328 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
330 {
return !(__y < __x); }
332 template<
typename _Tp,
typename _Ref,
typename _Ptr>
336 {
return !(__x < __y); }
338 template<
typename _Tp,
typename _RefL,
typename _PtrL,
339 typename _RefR,
typename _PtrR>
343 {
return !(__x < __y); }
349 template<
typename _Tp,
typename _Ref,
typename _Ptr>
350 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
354 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
356 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
357 + (__y._M_last - __y._M_cur);
360 template<
typename _Tp,
typename _RefL,
typename _PtrL,
361 typename _RefR,
typename _PtrR>
362 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
366 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
368 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
369 + (__y._M_last - __y._M_cur);
372 template<
typename _Tp,
typename _Ref,
typename _Ptr>
376 {
return __x + __n; }
378 template<
typename _Tp>
383 template<
typename _Tp>
389 template<
typename _Tp>
398 template<
typename _Tp>
404 template<
typename _Tp>
410 const _Tp&,
const _Tp*>(__first),
412 const _Tp&,
const _Tp*>(__last),
415 #if __cplusplus >= 201103L 416 template<
typename _Tp>
422 template<
typename _Tp>
431 template<
typename _Tp>
437 template<
typename _Tp>
443 const _Tp&,
const _Tp*>(__first),
445 const _Tp&,
const _Tp*>(__last),
459 template<
typename _Tp,
typename _Alloc>
464 rebind<_Tp>::other _Tp_alloc_type;
467 #if __cplusplus < 201103L 469 typedef const _Tp* _Ptr_const;
471 typedef typename _Alloc_traits::pointer _Ptr;
472 typedef typename _Alloc_traits::const_pointer _Ptr_const;
475 typedef typename _Alloc_traits::template rebind<_Ptr>::other
480 typedef _Alloc allocator_type;
481 typedef typename _Alloc_traits::size_type size_type;
484 get_allocator()
const _GLIBCXX_NOEXCEPT
485 {
return allocator_type(_M_get_Tp_allocator()); }
492 { _M_initialize_map(0); }
496 { _M_initialize_map(__num_elements); }
498 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
500 { _M_initialize_map(__num_elements); }
506 #if __cplusplus >= 201103L 508 : _M_impl(__x._M_move_impl())
512 : _M_impl(std::move(__x._M_get_Tp_allocator()))
514 _M_initialize_map(0);
515 if (__x._M_impl._M_map)
516 this->_M_impl._M_swap_data(__x._M_impl);
526 if (__x.get_allocator() == __a)
528 if (__x._M_impl._M_map)
530 _M_initialize_map(0);
531 this->_M_impl._M_swap_data(__x._M_impl);
536 _M_initialize_map(__n);
544 typedef typename iterator::_Map_pointer _Map_pointer;
550 :
public _Tp_alloc_type
558 : _Tp_alloc_type(), _M_map(), _M_map_size(0),
559 _M_start(), _M_finish()
562 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
563 : _Tp_alloc_type(__a), _M_map(), _M_map_size(0),
564 _M_start(), _M_finish()
567 #if __cplusplus >= 201103L 568 _Deque_impl(_Deque_impl&&) =
default;
570 _Deque_impl(_Tp_alloc_type&& __a) noexcept
571 : _Tp_alloc_type(std::move(__a)), _M_map(), _M_map_size(0),
572 _M_start(), _M_finish()
576 void _M_swap_data(_Deque_impl& __x) _GLIBCXX_NOEXCEPT
579 swap(this->_M_start, __x._M_start);
580 swap(this->_M_finish, __x._M_finish);
581 swap(this->_M_map, __x._M_map);
582 swap(this->_M_map_size, __x._M_map_size);
587 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
588 {
return *
static_cast<_Tp_alloc_type*
>(&this->_M_impl); }
590 const _Tp_alloc_type&
591 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
592 {
return *
static_cast<const _Tp_alloc_type*
>(&this->_M_impl); }
595 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
596 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
602 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
606 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
609 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
613 _M_allocate_map(
size_t __n)
615 _Map_alloc_type __map_alloc = _M_get_map_allocator();
616 return _Map_alloc_traits::allocate(__map_alloc, __n);
620 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
622 _Map_alloc_type __map_alloc = _M_get_map_allocator();
623 _Map_alloc_traits::deallocate(__map_alloc, __p, __n);
627 void _M_initialize_map(
size_t);
628 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
629 void _M_destroy_nodes(_Map_pointer __nstart,
630 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
631 enum { _S_initial_map_size = 8 };
635 #if __cplusplus >= 201103L 641 return std::move(_M_impl);
644 _Tp_alloc_type __alloc{_M_get_Tp_allocator()};
646 _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
651 _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
652 _M_impl._M_swap_data(__ret);
653 _M_impl._M_swap_data(__empty._M_impl);
659 template<
typename _Tp,
typename _Alloc>
663 if (this->_M_impl._M_map)
665 _M_destroy_nodes(this->_M_impl._M_start._M_node,
666 this->_M_impl._M_finish._M_node + 1);
667 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
679 template<
typename _Tp,
typename _Alloc>
684 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
687 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
688 size_t(__num_nodes + 2));
689 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
696 _Map_pointer __nstart = (this->_M_impl._M_map
697 + (this->_M_impl._M_map_size - __num_nodes) / 2);
698 _Map_pointer __nfinish = __nstart + __num_nodes;
701 { _M_create_nodes(__nstart, __nfinish); }
704 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
705 this->_M_impl._M_map = _Map_pointer();
706 this->_M_impl._M_map_size = 0;
707 __throw_exception_again;
710 this->_M_impl._M_start._M_set_node(__nstart);
711 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
712 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
713 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
715 % __deque_buf_size(
sizeof(_Tp)));
718 template<
typename _Tp,
typename _Alloc>
726 for (__cur = __nstart; __cur < __nfinish; ++__cur)
727 *__cur = this->_M_allocate_node();
731 _M_destroy_nodes(__nstart, __cur);
732 __throw_exception_again;
736 template<
typename _Tp,
typename _Alloc>
740 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
742 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
743 _M_deallocate_node(*__n);
830 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
834 typedef typename _Alloc::value_type _Alloc_value_type;
835 #if __cplusplus < 201103L 836 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
838 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
841 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
843 typedef typename _Base::_Map_pointer _Map_pointer;
846 typedef _Tp value_type;
847 typedef typename _Alloc_traits::pointer pointer;
848 typedef typename _Alloc_traits::const_pointer const_pointer;
849 typedef typename _Alloc_traits::reference reference;
850 typedef typename _Alloc_traits::const_reference const_reference;
855 typedef size_t size_type;
856 typedef ptrdiff_t difference_type;
857 typedef _Alloc allocator_type;
860 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
861 {
return __deque_buf_size(
sizeof(_Tp)); }
864 using _Base::_M_initialize_map;
865 using _Base::_M_create_nodes;
866 using _Base::_M_destroy_nodes;
867 using _Base::_M_allocate_node;
868 using _Base::_M_deallocate_node;
869 using _Base::_M_allocate_map;
870 using _Base::_M_deallocate_map;
871 using _Base::_M_get_Tp_allocator;
877 using _Base::_M_impl;
896 #if __cplusplus >= 201103L 906 deque(size_type __n,
const allocator_type& __a = allocator_type())
908 { _M_default_initialize(); }
918 deque(size_type __n,
const value_type& __value,
919 const allocator_type& __a = allocator_type())
921 { _M_fill_initialize(__value); }
932 deque(size_type __n,
const value_type& __value = value_type(),
933 const allocator_type& __a = allocator_type())
935 { _M_fill_initialize(__value); }
946 : _Base(_Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()),
948 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
949 this->_M_impl._M_start,
950 _M_get_Tp_allocator()); }
952 #if __cplusplus >= 201103L 961 : _Base(
std::move(__x)) { }
965 : _Base(__a, __x.size())
966 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
967 this->_M_impl._M_start,
968 _M_get_Tp_allocator()); }
972 : _Base(
std::move(__x), __a, __x.size())
974 if (__x.get_allocator() != __a)
976 std::__uninitialized_move_a(__x.begin(), __x.end(),
977 this->_M_impl._M_start,
978 _M_get_Tp_allocator());
995 const allocator_type& __a = allocator_type())
998 _M_range_initialize(__l.begin(), __l.end(),
1018 #if __cplusplus >= 201103L 1019 template<
typename _InputIterator,
1020 typename = std::_RequireInputIter<_InputIterator>>
1021 deque(_InputIterator __first, _InputIterator __last,
1022 const allocator_type& __a = allocator_type())
1024 { _M_initialize_dispatch(__first, __last, __false_type()); }
1026 template<
typename _InputIterator>
1027 deque(_InputIterator __first, _InputIterator __last,
1028 const allocator_type& __a = allocator_type())
1032 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1033 _M_initialize_dispatch(__first, __last, _Integral());
1043 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1055 operator=(
const deque& __x);
1057 #if __cplusplus >= 201103L 1070 _M_move_assign1(std::move(__x), __always_equal{});
1088 _M_assign_aux(__l.begin(), __l.end(),
1105 assign(size_type __n,
const value_type& __val)
1106 { _M_fill_assign(__n, __val); }
1120 #if __cplusplus >= 201103L 1121 template<
typename _InputIterator,
1122 typename = std::_RequireInputIter<_InputIterator>>
1124 assign(_InputIterator __first, _InputIterator __last)
1125 { _M_assign_dispatch(__first, __last, __false_type()); }
1127 template<
typename _InputIterator>
1129 assign(_InputIterator __first, _InputIterator __last)
1131 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1132 _M_assign_dispatch(__first, __last, _Integral());
1136 #if __cplusplus >= 201103L 1156 {
return _Base::get_allocator(); }
1165 {
return this->_M_impl._M_start; }
1173 {
return this->_M_impl._M_start; }
1182 {
return this->_M_impl._M_finish; }
1191 {
return this->_M_impl._M_finish; }
1200 {
return reverse_iterator(this->_M_impl._M_finish); }
1207 const_reverse_iterator
1209 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1218 {
return reverse_iterator(this->_M_impl._M_start); }
1225 const_reverse_iterator
1227 {
return const_reverse_iterator(this->_M_impl._M_start); }
1229 #if __cplusplus >= 201103L 1236 {
return this->_M_impl._M_start; }
1245 {
return this->_M_impl._M_finish; }
1252 const_reverse_iterator
1254 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1261 const_reverse_iterator
1263 {
return const_reverse_iterator(this->_M_impl._M_start); }
1270 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1275 {
return _Alloc_traits::max_size(_M_get_Tp_allocator()); }
1277 #if __cplusplus >= 201103L 1290 const size_type __len = size();
1291 if (__new_size > __len)
1292 _M_default_append(__new_size - __len);
1293 else if (__new_size < __len)
1294 _M_erase_at_end(this->_M_impl._M_start
1295 + difference_type(__new_size));
1310 resize(size_type __new_size,
const value_type& __x)
1312 const size_type __len = size();
1313 if (__new_size > __len)
1314 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1315 else if (__new_size < __len)
1316 _M_erase_at_end(this->_M_impl._M_start
1317 + difference_type(__new_size));
1332 resize(size_type __new_size, value_type __x = value_type())
1334 const size_type __len = size();
1335 if (__new_size > __len)
1336 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1337 else if (__new_size < __len)
1338 _M_erase_at_end(this->_M_impl._M_start
1339 + difference_type(__new_size));
1343 #if __cplusplus >= 201103L 1347 { _M_shrink_to_fit(); }
1356 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1373 __glibcxx_requires_subscript(__n);
1374 return this->_M_impl._M_start[difference_type(__n)];
1391 __glibcxx_requires_subscript(__n);
1392 return this->_M_impl._M_start[difference_type(__n)];
1400 if (__n >= this->size())
1401 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1402 "(which is %zu)>= this->size() " 1422 _M_range_check(__n);
1423 return (*
this)[__n];
1440 _M_range_check(__n);
1441 return (*
this)[__n];
1451 __glibcxx_requires_nonempty();
1462 __glibcxx_requires_nonempty();
1473 __glibcxx_requires_nonempty();
1474 iterator __tmp =
end();
1486 __glibcxx_requires_nonempty();
1487 const_iterator __tmp =
end();
1505 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1507 _Alloc_traits::construct(this->_M_impl,
1508 this->_M_impl._M_start._M_cur - 1,
1510 --this->_M_impl._M_start._M_cur;
1513 _M_push_front_aux(__x);
1516 #if __cplusplus >= 201103L 1518 push_front(value_type&& __x)
1519 { emplace_front(std::move(__x)); }
1521 template<
typename... _Args>
1522 #if __cplusplus > 201402L 1527 emplace_front(_Args&&... __args);
1542 if (this->_M_impl._M_finish._M_cur
1543 != this->_M_impl._M_finish._M_last - 1)
1545 _Alloc_traits::construct(this->_M_impl,
1546 this->_M_impl._M_finish._M_cur, __x);
1547 ++this->_M_impl._M_finish._M_cur;
1550 _M_push_back_aux(__x);
1553 #if __cplusplus >= 201103L 1555 push_back(value_type&& __x)
1556 { emplace_back(std::move(__x)); }
1558 template<
typename... _Args>
1559 #if __cplusplus > 201402L 1564 emplace_back(_Args&&... __args);
1578 __glibcxx_requires_nonempty();
1579 if (this->_M_impl._M_start._M_cur
1580 != this->_M_impl._M_start._M_last - 1)
1582 _Alloc_traits::destroy(this->_M_impl,
1583 this->_M_impl._M_start._M_cur);
1584 ++this->_M_impl._M_start._M_cur;
1601 __glibcxx_requires_nonempty();
1602 if (this->_M_impl._M_finish._M_cur
1603 != this->_M_impl._M_finish._M_first)
1605 --this->_M_impl._M_finish._M_cur;
1606 _Alloc_traits::destroy(this->_M_impl,
1607 this->_M_impl._M_finish._M_cur);
1613 #if __cplusplus >= 201103L 1623 template<
typename... _Args>
1625 emplace(const_iterator __position, _Args&&... __args);
1637 insert(const_iterator __position,
const value_type& __x);
1649 insert(iterator __position,
const value_type& __x);
1652 #if __cplusplus >= 201103L 1663 insert(const_iterator __position, value_type&& __x)
1664 {
return emplace(__position, std::move(__x)); }
1678 auto __offset = __p -
cbegin();
1679 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1681 return begin() + __offset;
1685 #if __cplusplus >= 201103L 1697 insert(const_iterator __position, size_type __n,
const value_type& __x)
1699 difference_type __offset = __position -
cbegin();
1700 _M_fill_insert(__position._M_const_cast(), __n, __x);
1701 return begin() + __offset;
1714 insert(iterator __position, size_type __n,
const value_type& __x)
1715 { _M_fill_insert(__position, __n, __x); }
1718 #if __cplusplus >= 201103L 1730 template<
typename _InputIterator,
1731 typename = std::_RequireInputIter<_InputIterator>>
1733 insert(const_iterator __position, _InputIterator __first,
1734 _InputIterator __last)
1736 difference_type __offset = __position -
cbegin();
1737 _M_insert_dispatch(__position._M_const_cast(),
1738 __first, __last, __false_type());
1739 return begin() + __offset;
1752 template<
typename _InputIterator>
1754 insert(iterator __position, _InputIterator __first,
1755 _InputIterator __last)
1758 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1759 _M_insert_dispatch(__position, __first, __last, _Integral());
1777 #if __cplusplus >= 201103L 1780 erase(iterator __position)
1782 {
return _M_erase(__position._M_const_cast()); }
1801 #if __cplusplus >= 201103L 1802 erase(const_iterator __first, const_iterator __last)
1804 erase(iterator __first, iterator __last)
1806 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1822 #if __cplusplus >= 201103L 1823 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1824 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1826 _M_impl._M_swap_data(__x._M_impl);
1827 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1828 __x._M_get_Tp_allocator());
1839 { _M_erase_at_end(
begin()); }
1848 template<
typename _Integer>
1850 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1852 _M_initialize_map(static_cast<size_type>(__n));
1853 _M_fill_initialize(__x);
1857 template<
typename _InputIterator>
1859 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1862 _M_range_initialize(__first, __last,
1878 template<
typename _InputIterator>
1880 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1884 template<
typename _ForwardIterator>
1886 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1901 _M_fill_initialize(
const value_type& __value);
1903 #if __cplusplus >= 201103L 1906 _M_default_initialize();
1916 template<
typename _Integer>
1918 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1919 { _M_fill_assign(__n, __val); }
1922 template<
typename _InputIterator>
1924 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1929 template<
typename _InputIterator>
1931 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1935 template<
typename _ForwardIterator>
1937 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1943 _ForwardIterator __mid = __first;
1945 std::copy(__first, __mid,
begin());
1946 _M_range_insert_aux(
end(), __mid, __last,
1950 _M_erase_at_end(std::copy(__first, __last,
begin()));
1956 _M_fill_assign(size_type __n,
const value_type& __val)
1961 _M_fill_insert(
end(), __n - size(), __val);
1965 _M_erase_at_end(
begin() + difference_type(__n));
1972 #if __cplusplus < 201103L 1973 void _M_push_back_aux(
const value_type&);
1975 void _M_push_front_aux(
const value_type&);
1977 template<
typename... _Args>
1978 void _M_push_back_aux(_Args&&... __args);
1980 template<
typename... _Args>
1981 void _M_push_front_aux(_Args&&... __args);
1984 void _M_pop_back_aux();
1986 void _M_pop_front_aux();
1996 template<
typename _Integer>
1998 _M_insert_dispatch(iterator __pos,
1999 _Integer __n, _Integer __x, __true_type)
2000 { _M_fill_insert(__pos, __n, __x); }
2003 template<
typename _InputIterator>
2005 _M_insert_dispatch(iterator __pos,
2006 _InputIterator __first, _InputIterator __last,
2009 _M_range_insert_aux(__pos, __first, __last,
2014 template<
typename _InputIterator>
2016 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2020 template<
typename _ForwardIterator>
2022 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2029 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2032 #if __cplusplus < 201103L 2034 _M_insert_aux(iterator __pos,
const value_type& __x);
2036 template<
typename... _Args>
2038 _M_insert_aux(iterator __pos, _Args&&... __args);
2043 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2046 template<
typename _ForwardIterator>
2048 _M_insert_aux(iterator __pos,
2049 _ForwardIterator __first, _ForwardIterator __last,
2056 _M_destroy_data_aux(iterator __first, iterator __last);
2060 template<
typename _Alloc1>
2062 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2063 { _M_destroy_data_aux(__first, __last); }
2066 _M_destroy_data(iterator __first, iterator __last,
2069 if (!__has_trivial_destructor(value_type))
2070 _M_destroy_data_aux(__first, __last);
2075 _M_erase_at_begin(iterator __pos)
2077 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2078 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2079 this->_M_impl._M_start = __pos;
2085 _M_erase_at_end(iterator __pos)
2087 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2088 _M_destroy_nodes(__pos._M_node + 1,
2089 this->_M_impl._M_finish._M_node + 1);
2090 this->_M_impl._M_finish = __pos;
2094 _M_erase(iterator __pos);
2097 _M_erase(iterator __first, iterator __last);
2099 #if __cplusplus >= 201103L 2102 _M_default_append(size_type __n);
2113 const size_type __vacancies = this->_M_impl._M_start._M_cur
2114 - this->_M_impl._M_start._M_first;
2115 if (__n > __vacancies)
2116 _M_new_elements_at_front(__n - __vacancies);
2117 return this->_M_impl._M_start - difference_type(__n);
2123 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2124 - this->_M_impl._M_finish._M_cur) - 1;
2125 if (__n > __vacancies)
2126 _M_new_elements_at_back(__n - __vacancies);
2127 return this->_M_impl._M_finish + difference_type(__n);
2131 _M_new_elements_at_front(size_type __new_elements);
2134 _M_new_elements_at_back(size_type __new_elements);
2149 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2150 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2151 _M_reallocate_map(__nodes_to_add,
false);
2157 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2158 - this->_M_impl._M_map))
2159 _M_reallocate_map(__nodes_to_add,
true);
2163 _M_reallocate_map(size_type __nodes_to_add,
bool __add_at_front);
2166 #if __cplusplus >= 201103L 2172 this->_M_impl._M_swap_data(__x._M_impl);
2174 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2183 constexpr
bool __move_storage =
2184 _Alloc_traits::_S_propagate_on_move_assign();
2190 template<
typename... _Args>
2192 _M_replace_map(_Args&&... __args)
2195 deque __newobj(std::forward<_Args>(__args)...);
2198 _M_deallocate_node(*
begin()._M_node);
2199 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2200 this->_M_impl._M_map =
nullptr;
2201 this->_M_impl._M_map_size = 0;
2203 this->_M_impl._M_swap_data(__newobj._M_impl);
2211 auto __alloc = __x._M_get_Tp_allocator();
2214 _M_replace_map(std::move(__x));
2216 _M_get_Tp_allocator() = std::move(__alloc);
2224 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2228 _M_replace_map(std::move(__x), __x.get_allocator());
2234 _M_assign_aux(std::__make_move_if_noexcept_iterator(__x.begin()),
2235 std::__make_move_if_noexcept_iterator(__x.end()),
2254 template<
typename _Tp,
typename _Alloc>
2272 template<
typename _Tp,
typename _Alloc>
2274 operator<(const deque<_Tp, _Alloc>& __x,
2277 __y.begin(), __y.end()); }
2280 template<
typename _Tp,
typename _Alloc>
2284 {
return !(__x == __y); }
2287 template<
typename _Tp,
typename _Alloc>
2291 {
return __y < __x; }
2294 template<
typename _Tp,
typename _Alloc>
2296 operator<=(const deque<_Tp, _Alloc>& __x,
2298 {
return !(__y < __x); }
2301 template<
typename _Tp,
typename _Alloc>
2305 {
return !(__x < __y); }
2308 template<
typename _Tp,
typename _Alloc>
2311 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2314 #undef _GLIBCXX_DEQUE_BUF_SIZE 2316 _GLIBCXX_END_NAMESPACE_CONTAINER
Uniform interface to all pointer-like types.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
const_iterator begin() const noexcept
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
reference at(size_type __n)
Provides access to the data contained in the deque.
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
iterator begin() noexcept
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
size_type max_size() const noexcept
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
void _M_set_node(_Map_pointer __new_node) noexcept
reverse_iterator rbegin() noexcept
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
void _M_initialize_map(size_t)
Layout storage.
const_iterator cbegin() const noexcept
const_reverse_iterator crend() const noexcept
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
ISO C++ entities toplevel namespace is std.
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
void _M_range_check(size_type __n) const
Safety check used only from at().
const_reverse_iterator rbegin() const noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
const_reverse_iterator rend() const noexcept
deque(const allocator_type &__a)
Creates a deque with no elements.
bool empty() const noexcept
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
iterator erase(const_iterator __position)
Remove element at given position.
deque(const deque &__x, const allocator_type &__a)
Copy constructor with alternative allocator.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
Random-access iterators support a superset of bidirectional iterator operations.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
deque()
Creates a deque with no elements.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
size_type size() const noexcept
const_reference front() const noexcept
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
void push_back(const value_type &__x)
Add data to the end of the deque.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
void pop_back() noexcept
Removes last element.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
void swap(deque &__x) noexcept
Swaps data with another deque.
const_iterator end() const noexcept
The standard allocator, as per [20.4].
const_reference back() const noexcept
deque(const deque &__x)
Deque copy constructor.
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
const_iterator cend() const noexcept
__detected_or_t< typename is_empty< _Tp_alloc_type >::type, __equal, _Tp_alloc_type > is_always_equal
Whether all instances of the allocator type compare equal.
reference back() noexcept
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
void shrink_to_fit() noexcept
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
const_reverse_iterator crbegin() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
reverse_iterator rend() noexcept
void push_front(const value_type &__x)
Add data to the front of the deque.
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
void pop_front() noexcept
Removes first element.
deque(deque &&__x)
Deque move constructor.
Uniform interface to C++98 and C++11 allocators.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
reference front() noexcept
Forward iterators support a superset of input iterator operations.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.