57 #define _STL_DEQUE_H 1 62 #if __cplusplus >= 201103L 66 namespace std _GLIBCXX_VISIBILITY(default)
68 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
84 #ifndef _GLIBCXX_DEQUE_BUF_SIZE 85 #define _GLIBCXX_DEQUE_BUF_SIZE 512 88 _GLIBCXX_CONSTEXPR
inline size_t 89 __deque_buf_size(
size_t __size)
105 template<
typename _Tp,
typename _Ref,
typename _Ptr>
108 #if __cplusplus < 201103L 111 typedef _Tp* _Elt_pointer;
112 typedef _Tp** _Map_pointer;
115 template<
typename _Up>
117 template<
typename _CvTp>
122 typedef __ptr_to<_Tp> _Elt_pointer;
123 typedef __ptr_to<_Elt_pointer> _Map_pointer;
126 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
127 {
return __deque_buf_size(
sizeof(_Tp)); }
130 typedef _Tp value_type;
131 typedef _Ptr pointer;
132 typedef _Ref reference;
133 typedef size_t size_type;
134 typedef ptrdiff_t difference_type;
138 _Elt_pointer _M_first;
139 _Elt_pointer _M_last;
140 _Map_pointer _M_node;
143 : _M_cur(__x), _M_first(*__y),
144 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
147 : _M_cur(), _M_first(), _M_last(), _M_node() { }
150 : _M_cur(__x._M_cur), _M_first(__x._M_first),
151 _M_last(__x._M_last), _M_node(__x._M_node) { }
154 _M_const_cast()
const _GLIBCXX_NOEXCEPT
155 {
return iterator(_M_cur, _M_node); }
158 operator*()
const _GLIBCXX_NOEXCEPT
162 operator->()
const _GLIBCXX_NOEXCEPT
166 operator++() _GLIBCXX_NOEXCEPT
169 if (_M_cur == _M_last)
178 operator++(
int) _GLIBCXX_NOEXCEPT
186 operator--() _GLIBCXX_NOEXCEPT
188 if (_M_cur == _M_first)
198 operator--(
int) _GLIBCXX_NOEXCEPT
206 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
208 const difference_type __offset = __n + (_M_cur - _M_first);
209 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
213 const difference_type __node_offset =
214 __offset > 0 ? __offset / difference_type(_S_buffer_size())
215 : -difference_type((-__offset - 1)
216 / _S_buffer_size()) - 1;
218 _M_cur = _M_first + (__offset - __node_offset
219 * difference_type(_S_buffer_size()));
225 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
232 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
233 {
return *
this += -__n; }
236 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
243 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
244 {
return *(*
this + __n); }
254 _M_node = __new_node;
255 _M_first = *__new_node;
256 _M_last = _M_first + difference_type(_S_buffer_size());
263 template<
typename _Tp,
typename _Ref,
typename _Ptr>
267 {
return __x._M_cur == __y._M_cur; }
269 template<
typename _Tp,
typename _RefL,
typename _PtrL,
270 typename _RefR,
typename _PtrR>
274 {
return __x._M_cur == __y._M_cur; }
276 template<
typename _Tp,
typename _Ref,
typename _Ptr>
280 {
return !(__x == __y); }
282 template<
typename _Tp,
typename _RefL,
typename _PtrL,
283 typename _RefR,
typename _PtrR>
287 {
return !(__x == __y); }
289 template<
typename _Tp,
typename _Ref,
typename _Ptr>
291 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
293 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
294 : (__x._M_node < __y._M_node); }
296 template<
typename _Tp,
typename _RefL,
typename _PtrL,
297 typename _RefR,
typename _PtrR>
299 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
301 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
302 : (__x._M_node < __y._M_node); }
304 template<
typename _Tp,
typename _Ref,
typename _Ptr>
308 {
return __y < __x; }
310 template<
typename _Tp,
typename _RefL,
typename _PtrL,
311 typename _RefR,
typename _PtrR>
315 {
return __y < __x; }
317 template<
typename _Tp,
typename _Ref,
typename _Ptr>
319 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
321 {
return !(__y < __x); }
323 template<
typename _Tp,
typename _RefL,
typename _PtrL,
324 typename _RefR,
typename _PtrR>
326 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
328 {
return !(__y < __x); }
330 template<
typename _Tp,
typename _Ref,
typename _Ptr>
334 {
return !(__x < __y); }
336 template<
typename _Tp,
typename _RefL,
typename _PtrL,
337 typename _RefR,
typename _PtrR>
341 {
return !(__x < __y); }
347 template<
typename _Tp,
typename _Ref,
typename _Ptr>
348 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
352 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
354 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
355 + (__y._M_last - __y._M_cur);
358 template<
typename _Tp,
typename _RefL,
typename _PtrL,
359 typename _RefR,
typename _PtrR>
360 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
364 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
366 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
367 + (__y._M_last - __y._M_cur);
370 template<
typename _Tp,
typename _Ref,
typename _Ptr>
374 {
return __x + __n; }
376 template<
typename _Tp>
381 template<
typename _Tp>
387 template<
typename _Tp>
396 template<
typename _Tp>
402 template<
typename _Tp>
408 const _Tp&,
const _Tp*>(__first),
410 const _Tp&,
const _Tp*>(__last),
413 #if __cplusplus >= 201103L 414 template<
typename _Tp>
420 template<
typename _Tp>
429 template<
typename _Tp>
435 template<
typename _Tp>
441 const _Tp&,
const _Tp*>(__first),
443 const _Tp&,
const _Tp*>(__last),
457 template<
typename _Tp,
typename _Alloc>
462 rebind<_Tp>::other _Tp_alloc_type;
465 #if __cplusplus < 201103L 467 typedef const _Tp* _Ptr_const;
469 typedef typename _Alloc_traits::pointer _Ptr;
470 typedef typename _Alloc_traits::const_pointer _Ptr_const;
473 typedef typename _Alloc_traits::template rebind<_Ptr>::other
478 typedef _Alloc allocator_type;
479 typedef typename _Alloc_traits::size_type size_type;
482 get_allocator()
const _GLIBCXX_NOEXCEPT
483 {
return allocator_type(_M_get_Tp_allocator()); }
490 { _M_initialize_map(0); }
494 { _M_initialize_map(__num_elements); }
496 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
498 { _M_initialize_map(__num_elements); }
504 #if __cplusplus >= 201103L 506 : _M_impl(__x._M_move_impl())
510 : _M_impl(std::move(__x._M_get_Tp_allocator()))
512 _M_initialize_map(0);
513 if (__x._M_impl._M_map)
514 this->_M_impl._M_swap_data(__x._M_impl);
524 if (__x.get_allocator() == __a)
526 if (__x._M_impl._M_map)
528 _M_initialize_map(0);
529 this->_M_impl._M_swap_data(__x._M_impl);
534 _M_initialize_map(__n);
542 typedef typename iterator::_Map_pointer _Map_pointer;
548 :
public _Tp_alloc_type
556 : _Tp_alloc_type(), _M_map(), _M_map_size(0),
557 _M_start(), _M_finish()
560 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
561 : _Tp_alloc_type(__a), _M_map(), _M_map_size(0),
562 _M_start(), _M_finish()
565 #if __cplusplus >= 201103L 566 _Deque_impl(_Deque_impl&&) =
default;
568 _Deque_impl(_Tp_alloc_type&& __a) noexcept
569 : _Tp_alloc_type(std::move(__a)), _M_map(), _M_map_size(0),
570 _M_start(), _M_finish()
574 void _M_swap_data(_Deque_impl& __x) _GLIBCXX_NOEXCEPT
577 swap(this->_M_start, __x._M_start);
578 swap(this->_M_finish, __x._M_finish);
579 swap(this->_M_map, __x._M_map);
580 swap(this->_M_map_size, __x._M_map_size);
585 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
586 {
return *
static_cast<_Tp_alloc_type*
>(&this->_M_impl); }
588 const _Tp_alloc_type&
589 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
590 {
return *
static_cast<const _Tp_alloc_type*
>(&this->_M_impl); }
593 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
594 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
600 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
604 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
607 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
611 _M_allocate_map(
size_t __n)
613 _Map_alloc_type __map_alloc = _M_get_map_allocator();
614 return _Map_alloc_traits::allocate(__map_alloc, __n);
618 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
620 _Map_alloc_type __map_alloc = _M_get_map_allocator();
621 _Map_alloc_traits::deallocate(__map_alloc, __p, __n);
625 void _M_initialize_map(
size_t);
626 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
627 void _M_destroy_nodes(_Map_pointer __nstart,
628 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
629 enum { _S_initial_map_size = 8 };
633 #if __cplusplus >= 201103L 639 return std::move(_M_impl);
642 _Tp_alloc_type __alloc{_M_get_Tp_allocator()};
644 _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
649 _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
650 _M_impl._M_swap_data(__ret);
651 _M_impl._M_swap_data(__empty._M_impl);
657 template<
typename _Tp,
typename _Alloc>
661 if (this->_M_impl._M_map)
663 _M_destroy_nodes(this->_M_impl._M_start._M_node,
664 this->_M_impl._M_finish._M_node + 1);
665 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
677 template<
typename _Tp,
typename _Alloc>
682 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
685 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
686 size_t(__num_nodes + 2));
687 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
694 _Map_pointer __nstart = (this->_M_impl._M_map
695 + (this->_M_impl._M_map_size - __num_nodes) / 2);
696 _Map_pointer __nfinish = __nstart + __num_nodes;
699 { _M_create_nodes(__nstart, __nfinish); }
702 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
703 this->_M_impl._M_map = _Map_pointer();
704 this->_M_impl._M_map_size = 0;
705 __throw_exception_again;
708 this->_M_impl._M_start._M_set_node(__nstart);
709 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
710 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
711 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
713 % __deque_buf_size(
sizeof(_Tp)));
716 template<
typename _Tp,
typename _Alloc>
724 for (__cur = __nstart; __cur < __nfinish; ++__cur)
725 *__cur = this->_M_allocate_node();
729 _M_destroy_nodes(__nstart, __cur);
730 __throw_exception_again;
734 template<
typename _Tp,
typename _Alloc>
738 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
740 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
741 _M_deallocate_node(*__n);
828 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
832 typedef typename _Alloc::value_type _Alloc_value_type;
833 #if __cplusplus < 201103L 834 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
836 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
839 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
841 typedef typename _Base::_Map_pointer _Map_pointer;
844 typedef _Tp value_type;
845 typedef typename _Alloc_traits::pointer pointer;
846 typedef typename _Alloc_traits::const_pointer const_pointer;
847 typedef typename _Alloc_traits::reference reference;
848 typedef typename _Alloc_traits::const_reference const_reference;
853 typedef size_t size_type;
854 typedef ptrdiff_t difference_type;
855 typedef _Alloc allocator_type;
858 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
859 {
return __deque_buf_size(
sizeof(_Tp)); }
862 using _Base::_M_initialize_map;
863 using _Base::_M_create_nodes;
864 using _Base::_M_destroy_nodes;
865 using _Base::_M_allocate_node;
866 using _Base::_M_deallocate_node;
867 using _Base::_M_allocate_map;
868 using _Base::_M_deallocate_map;
869 using _Base::_M_get_Tp_allocator;
875 using _Base::_M_impl;
894 #if __cplusplus >= 201103L 904 deque(size_type __n,
const allocator_type& __a = allocator_type())
906 { _M_default_initialize(); }
916 deque(size_type __n,
const value_type& __value,
917 const allocator_type& __a = allocator_type())
919 { _M_fill_initialize(__value); }
930 deque(size_type __n,
const value_type& __value = value_type(),
931 const allocator_type& __a = allocator_type())
933 { _M_fill_initialize(__value); }
944 : _Base(_Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()),
946 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
947 this->_M_impl._M_start,
948 _M_get_Tp_allocator()); }
950 #if __cplusplus >= 201103L 959 : _Base(
std::move(__x)) { }
963 : _Base(__a, __x.size())
964 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
965 this->_M_impl._M_start,
966 _M_get_Tp_allocator()); }
970 : _Base(
std::move(__x), __a, __x.size())
972 if (__x.get_allocator() != __a)
974 std::__uninitialized_move_a(__x.begin(), __x.end(),
975 this->_M_impl._M_start,
976 _M_get_Tp_allocator());
993 const allocator_type& __a = allocator_type())
996 _M_range_initialize(__l.begin(), __l.end(),
1016 #if __cplusplus >= 201103L 1017 template<
typename _InputIterator,
1018 typename = std::_RequireInputIter<_InputIterator>>
1019 deque(_InputIterator __first, _InputIterator __last,
1020 const allocator_type& __a = allocator_type())
1022 { _M_initialize_dispatch(__first, __last, __false_type()); }
1024 template<
typename _InputIterator>
1025 deque(_InputIterator __first, _InputIterator __last,
1026 const allocator_type& __a = allocator_type())
1030 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1031 _M_initialize_dispatch(__first, __last, _Integral());
1041 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1051 operator=(
const deque& __x);
1053 #if __cplusplus >= 201103L 1066 _M_move_assign1(std::move(__x), __always_equal{});
1084 this->assign(__l.begin(), __l.end());
1100 assign(size_type __n,
const value_type& __val)
1101 { _M_fill_assign(__n, __val); }
1115 #if __cplusplus >= 201103L 1116 template<
typename _InputIterator,
1117 typename = std::_RequireInputIter<_InputIterator>>
1119 assign(_InputIterator __first, _InputIterator __last)
1120 { _M_assign_dispatch(__first, __last, __false_type()); }
1122 template<
typename _InputIterator>
1124 assign(_InputIterator __first, _InputIterator __last)
1126 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1127 _M_assign_dispatch(__first, __last, _Integral());
1131 #if __cplusplus >= 201103L 1145 { this->assign(__l.begin(), __l.end()); }
1151 {
return _Base::get_allocator(); }
1160 {
return this->_M_impl._M_start; }
1168 {
return this->_M_impl._M_start; }
1177 {
return this->_M_impl._M_finish; }
1186 {
return this->_M_impl._M_finish; }
1195 {
return reverse_iterator(this->_M_impl._M_finish); }
1202 const_reverse_iterator
1204 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1213 {
return reverse_iterator(this->_M_impl._M_start); }
1220 const_reverse_iterator
1222 {
return const_reverse_iterator(this->_M_impl._M_start); }
1224 #if __cplusplus >= 201103L 1231 {
return this->_M_impl._M_start; }
1240 {
return this->_M_impl._M_finish; }
1247 const_reverse_iterator
1249 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1256 const_reverse_iterator
1258 {
return const_reverse_iterator(this->_M_impl._M_start); }
1265 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1270 {
return _Alloc_traits::max_size(_M_get_Tp_allocator()); }
1272 #if __cplusplus >= 201103L 1285 const size_type __len = size();
1286 if (__new_size > __len)
1287 _M_default_append(__new_size - __len);
1288 else if (__new_size < __len)
1289 _M_erase_at_end(this->_M_impl._M_start
1290 + difference_type(__new_size));
1305 resize(size_type __new_size,
const value_type& __x)
1307 const size_type __len = size();
1308 if (__new_size > __len)
1309 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1310 else if (__new_size < __len)
1311 _M_erase_at_end(this->_M_impl._M_start
1312 + difference_type(__new_size));
1327 resize(size_type __new_size, value_type __x = value_type())
1329 const size_type __len = size();
1330 if (__new_size > __len)
1331 insert(this->_M_impl._M_finish, __new_size - __len, __x);
1332 else if (__new_size < __len)
1333 _M_erase_at_end(this->_M_impl._M_start
1334 + difference_type(__new_size));
1338 #if __cplusplus >= 201103L 1342 { _M_shrink_to_fit(); }
1351 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1367 {
return this->_M_impl._M_start[difference_type(__n)]; }
1382 {
return this->_M_impl._M_start[difference_type(__n)]; }
1389 if (__n >= this->size())
1390 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1391 "(which is %zu)>= this->size() " 1411 _M_range_check(__n);
1412 return (*
this)[__n];
1429 _M_range_check(__n);
1430 return (*
this)[__n];
1439 {
return *
begin(); }
1447 {
return *
begin(); }
1456 iterator __tmp =
end();
1468 const_iterator __tmp =
end();
1486 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1488 _Alloc_traits::construct(this->_M_impl,
1489 this->_M_impl._M_start._M_cur - 1,
1491 --this->_M_impl._M_start._M_cur;
1494 _M_push_front_aux(__x);
1497 #if __cplusplus >= 201103L 1499 push_front(value_type&& __x)
1500 { emplace_front(std::move(__x)); }
1502 template<
typename... _Args>
1504 emplace_front(_Args&&... __args);
1519 if (this->_M_impl._M_finish._M_cur
1520 != this->_M_impl._M_finish._M_last - 1)
1522 _Alloc_traits::construct(this->_M_impl,
1523 this->_M_impl._M_finish._M_cur, __x);
1524 ++this->_M_impl._M_finish._M_cur;
1527 _M_push_back_aux(__x);
1530 #if __cplusplus >= 201103L 1532 push_back(value_type&& __x)
1533 { emplace_back(std::move(__x)); }
1535 template<
typename... _Args>
1537 emplace_back(_Args&&... __args);
1551 if (this->_M_impl._M_start._M_cur
1552 != this->_M_impl._M_start._M_last - 1)
1554 _Alloc_traits::destroy(this->_M_impl,
1555 this->_M_impl._M_start._M_cur);
1556 ++this->_M_impl._M_start._M_cur;
1573 if (this->_M_impl._M_finish._M_cur
1574 != this->_M_impl._M_finish._M_first)
1576 --this->_M_impl._M_finish._M_cur;
1577 _Alloc_traits::destroy(this->_M_impl,
1578 this->_M_impl._M_finish._M_cur);
1584 #if __cplusplus >= 201103L 1594 template<
typename... _Args>
1596 emplace(const_iterator __position, _Args&&... __args);
1608 insert(const_iterator __position,
const value_type& __x);
1620 insert(iterator __position,
const value_type& __x);
1623 #if __cplusplus >= 201103L 1634 insert(const_iterator __position, value_type&& __x)
1635 {
return emplace(__position, std::move(__x)); }
1648 {
return this->insert(__p, __l.begin(), __l.end()); }
1651 #if __cplusplus >= 201103L 1663 insert(const_iterator __position, size_type __n,
const value_type& __x)
1665 difference_type __offset = __position -
cbegin();
1666 _M_fill_insert(__position._M_const_cast(), __n, __x);
1667 return begin() + __offset;
1680 insert(iterator __position, size_type __n,
const value_type& __x)
1681 { _M_fill_insert(__position, __n, __x); }
1684 #if __cplusplus >= 201103L 1696 template<
typename _InputIterator,
1697 typename = std::_RequireInputIter<_InputIterator>>
1699 insert(const_iterator __position, _InputIterator __first,
1700 _InputIterator __last)
1702 difference_type __offset = __position -
cbegin();
1703 _M_insert_dispatch(__position._M_const_cast(),
1704 __first, __last, __false_type());
1705 return begin() + __offset;
1718 template<
typename _InputIterator>
1720 insert(iterator __position, _InputIterator __first,
1721 _InputIterator __last)
1724 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1725 _M_insert_dispatch(__position, __first, __last, _Integral());
1743 #if __cplusplus >= 201103L 1746 erase(iterator __position)
1748 {
return _M_erase(__position._M_const_cast()); }
1767 #if __cplusplus >= 201103L 1768 erase(const_iterator __first, const_iterator __last)
1770 erase(iterator __first, iterator __last)
1772 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1786 _M_impl._M_swap_data(__x._M_impl);
1787 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1788 __x._M_get_Tp_allocator());
1799 { _M_erase_at_end(
begin()); }
1808 template<
typename _Integer>
1810 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1812 _M_initialize_map(static_cast<size_type>(__n));
1813 _M_fill_initialize(__x);
1817 template<
typename _InputIterator>
1819 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1822 typedef typename std::iterator_traits<_InputIterator>::
1823 iterator_category _IterCategory;
1824 _M_range_initialize(__first, __last, _IterCategory());
1839 template<
typename _InputIterator>
1841 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1845 template<
typename _ForwardIterator>
1847 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1862 _M_fill_initialize(
const value_type& __value);
1864 #if __cplusplus >= 201103L 1867 _M_default_initialize();
1877 template<
typename _Integer>
1879 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1880 { _M_fill_assign(__n, __val); }
1883 template<
typename _InputIterator>
1885 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1888 typedef typename std::iterator_traits<_InputIterator>::
1889 iterator_category _IterCategory;
1890 _M_assign_aux(__first, __last, _IterCategory());
1894 template<
typename _InputIterator>
1896 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1900 template<
typename _ForwardIterator>
1902 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1908 _ForwardIterator __mid = __first;
1910 std::copy(__first, __mid,
begin());
1911 insert(
end(), __mid, __last);
1914 _M_erase_at_end(std::copy(__first, __last,
begin()));
1920 _M_fill_assign(size_type __n,
const value_type& __val)
1925 insert(
end(), __n - size(), __val);
1929 _M_erase_at_end(
begin() + difference_type(__n));
1936 #if __cplusplus < 201103L 1937 void _M_push_back_aux(
const value_type&);
1939 void _M_push_front_aux(
const value_type&);
1941 template<
typename... _Args>
1942 void _M_push_back_aux(_Args&&... __args);
1944 template<
typename... _Args>
1945 void _M_push_front_aux(_Args&&... __args);
1948 void _M_pop_back_aux();
1950 void _M_pop_front_aux();
1960 template<
typename _Integer>
1962 _M_insert_dispatch(iterator __pos,
1963 _Integer __n, _Integer __x, __true_type)
1964 { _M_fill_insert(__pos, __n, __x); }
1967 template<
typename _InputIterator>
1969 _M_insert_dispatch(iterator __pos,
1970 _InputIterator __first, _InputIterator __last,
1973 typedef typename std::iterator_traits<_InputIterator>::
1974 iterator_category _IterCategory;
1975 _M_range_insert_aux(__pos, __first, __last, _IterCategory());
1979 template<
typename _InputIterator>
1981 _M_range_insert_aux(iterator __pos, _InputIterator __first,
1985 template<
typename _ForwardIterator>
1987 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
1994 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1997 #if __cplusplus < 201103L 1999 _M_insert_aux(iterator __pos,
const value_type& __x);
2001 template<
typename... _Args>
2003 _M_insert_aux(iterator __pos, _Args&&... __args);
2008 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2011 template<
typename _ForwardIterator>
2013 _M_insert_aux(iterator __pos,
2014 _ForwardIterator __first, _ForwardIterator __last,
2021 _M_destroy_data_aux(iterator __first, iterator __last);
2025 template<
typename _Alloc1>
2027 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2028 { _M_destroy_data_aux(__first, __last); }
2031 _M_destroy_data(iterator __first, iterator __last,
2034 if (!__has_trivial_destructor(value_type))
2035 _M_destroy_data_aux(__first, __last);
2040 _M_erase_at_begin(iterator __pos)
2042 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2043 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2044 this->_M_impl._M_start = __pos;
2050 _M_erase_at_end(iterator __pos)
2052 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2053 _M_destroy_nodes(__pos._M_node + 1,
2054 this->_M_impl._M_finish._M_node + 1);
2055 this->_M_impl._M_finish = __pos;
2059 _M_erase(iterator __pos);
2062 _M_erase(iterator __first, iterator __last);
2064 #if __cplusplus >= 201103L 2067 _M_default_append(size_type __n);
2078 const size_type __vacancies = this->_M_impl._M_start._M_cur
2079 - this->_M_impl._M_start._M_first;
2080 if (__n > __vacancies)
2081 _M_new_elements_at_front(__n - __vacancies);
2082 return this->_M_impl._M_start - difference_type(__n);
2088 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2089 - this->_M_impl._M_finish._M_cur) - 1;
2090 if (__n > __vacancies)
2091 _M_new_elements_at_back(__n - __vacancies);
2092 return this->_M_impl._M_finish + difference_type(__n);
2096 _M_new_elements_at_front(size_type __new_elements);
2099 _M_new_elements_at_back(size_type __new_elements);
2114 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2115 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2116 _M_reallocate_map(__nodes_to_add,
false);
2122 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2123 - this->_M_impl._M_map))
2124 _M_reallocate_map(__nodes_to_add,
true);
2128 _M_reallocate_map(size_type __nodes_to_add,
bool __add_at_front);
2131 #if __cplusplus >= 201103L 2137 this->_M_impl._M_swap_data(__x._M_impl);
2139 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2148 constexpr
bool __move_storage =
2149 _Alloc_traits::_S_propagate_on_move_assign();
2155 template<
typename... _Args>
2157 _M_replace_map(_Args&&... __args)
2160 deque __newobj(std::forward<_Args>(__args)...);
2163 _M_deallocate_node(*
begin()._M_node);
2164 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2165 this->_M_impl._M_map =
nullptr;
2166 this->_M_impl._M_map_size = 0;
2168 this->_M_impl._M_swap_data(__newobj._M_impl);
2176 auto __alloc = __x._M_get_Tp_allocator();
2179 _M_replace_map(std::move(__x));
2181 _M_get_Tp_allocator() = std::move(__alloc);
2189 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2193 _M_replace_map(std::move(__x), __x.get_allocator());
2199 this->assign(std::__make_move_if_noexcept_iterator(__x.begin()),
2200 std::__make_move_if_noexcept_iterator(__x.end()));
2218 template<
typename _Tp,
typename _Alloc>
2236 template<
typename _Tp,
typename _Alloc>
2238 operator<(const deque<_Tp, _Alloc>& __x,
2241 __y.begin(), __y.end()); }
2244 template<
typename _Tp,
typename _Alloc>
2248 {
return !(__x == __y); }
2251 template<
typename _Tp,
typename _Alloc>
2255 {
return __y < __x; }
2258 template<
typename _Tp,
typename _Alloc>
2260 operator<=(const deque<_Tp, _Alloc>& __x,
2262 {
return !(__y < __x); }
2265 template<
typename _Tp,
typename _Alloc>
2269 {
return !(__x < __y); }
2272 template<
typename _Tp,
typename _Alloc>
2275 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2278 #undef _GLIBCXX_DEQUE_BUF_SIZE 2280 _GLIBCXX_END_NAMESPACE_CONTAINER
void pop_back() noexcept
Removes last element.
deque(const deque &__x, const allocator_type &__a)
Copy constructor with alternative allocator.
reverse_iterator rend() noexcept
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
The standard allocator, as per [20.4].
void _M_range_check(size_type __n) const
Safety check used only from at().
void _M_initialize_map(size_t)
Layout storage.
const_reverse_iterator rbegin() const noexcept
Uniform interface to C++98 and C++11 allocators.
reference front() noexcept
void swap(deque &__x) noexcept
Swaps data with another deque.
deque(const deque &__x)
Deque copy constructor.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
const_reverse_iterator rend() const noexcept
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
const_iterator cend() const noexcept
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
deque(deque &&__x)
Deque move constructor.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
void push_front(const value_type &__x)
Add data to the front of the deque.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
iterator begin() noexcept
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
Uniform interface to all pointer-like types.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_reference back() const noexcept
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
const_reference front() const noexcept
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.
reverse_iterator rbegin() noexcept
const_iterator begin() const noexcept
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
void push_back(const value_type &__x)
Add data to the end of the deque.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
__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.
bool empty() const noexcept
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
reference back() noexcept
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
void pop_front() noexcept
Removes first element.
void _M_set_node(_Map_pointer __new_node) noexcept
const_reverse_iterator crend() const noexcept
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
deque()
Creates a deque with no elements.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
Random-access iterators support a superset of bidirectional iterator operations.
iterator erase(const_iterator __position)
Remove element at given position.
size_type max_size() const noexcept
reference at(size_type __n)
Provides access to the data contained in the deque.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
void shrink_to_fit() noexcept
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
Forward iterators support a superset of input iterator operations.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
const_iterator end() const noexcept
const_reverse_iterator crbegin() const noexcept
deque(const allocator_type &__a)
Creates a deque with no elements.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
ISO C++ entities toplevel namespace is std.
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
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.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
const_iterator cbegin() const noexcept
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
size_type size() const noexcept