10b57cec5SDimitry Andric// -*- C++ -*- 2*349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_DEQUE 110b57cec5SDimitry Andric#define _LIBCPP_DEQUE 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric deque synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> > 200b57cec5SDimitry Andricclass deque 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricpublic: 230b57cec5SDimitry Andric // types: 240b57cec5SDimitry Andric typedef T value_type; 250b57cec5SDimitry Andric typedef Allocator allocator_type; 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 280b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 290b57cec5SDimitry Andric typedef implementation-defined iterator; 300b57cec5SDimitry Andric typedef implementation-defined const_iterator; 310b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 320b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 350b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 360b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 370b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric // construct/copy/destroy: 400b57cec5SDimitry Andric deque() noexcept(is_nothrow_default_constructible<allocator_type>::value); 410b57cec5SDimitry Andric explicit deque(const allocator_type& a); 420b57cec5SDimitry Andric explicit deque(size_type n); 430b57cec5SDimitry Andric explicit deque(size_type n, const allocator_type& a); // C++14 440b57cec5SDimitry Andric deque(size_type n, const value_type& v); 450b57cec5SDimitry Andric deque(size_type n, const value_type& v, const allocator_type& a); 460b57cec5SDimitry Andric template <class InputIterator> 470b57cec5SDimitry Andric deque(InputIterator f, InputIterator l); 480b57cec5SDimitry Andric template <class InputIterator> 490b57cec5SDimitry Andric deque(InputIterator f, InputIterator l, const allocator_type& a); 500b57cec5SDimitry Andric deque(const deque& c); 510b57cec5SDimitry Andric deque(deque&& c) 520b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 530b57cec5SDimitry Andric deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); 540b57cec5SDimitry Andric deque(const deque& c, const allocator_type& a); 550b57cec5SDimitry Andric deque(deque&& c, const allocator_type& a); 560b57cec5SDimitry Andric ~deque(); 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric deque& operator=(const deque& c); 590b57cec5SDimitry Andric deque& operator=(deque&& c) 600b57cec5SDimitry Andric noexcept( 610b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value && 620b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value); 630b57cec5SDimitry Andric deque& operator=(initializer_list<value_type> il); 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric template <class InputIterator> 660b57cec5SDimitry Andric void assign(InputIterator f, InputIterator l); 670b57cec5SDimitry Andric void assign(size_type n, const value_type& v); 680b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 710b57cec5SDimitry Andric 720b57cec5SDimitry Andric // iterators: 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric iterator begin() noexcept; 750b57cec5SDimitry Andric const_iterator begin() const noexcept; 760b57cec5SDimitry Andric iterator end() noexcept; 770b57cec5SDimitry Andric const_iterator end() const noexcept; 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 800b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 810b57cec5SDimitry Andric reverse_iterator rend() noexcept; 820b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 850b57cec5SDimitry Andric const_iterator cend() const noexcept; 860b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 870b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric // capacity: 900b57cec5SDimitry Andric size_type size() const noexcept; 910b57cec5SDimitry Andric size_type max_size() const noexcept; 920b57cec5SDimitry Andric void resize(size_type n); 930b57cec5SDimitry Andric void resize(size_type n, const value_type& v); 940b57cec5SDimitry Andric void shrink_to_fit(); 950b57cec5SDimitry Andric bool empty() const noexcept; 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric // element access: 980b57cec5SDimitry Andric reference operator[](size_type i); 990b57cec5SDimitry Andric const_reference operator[](size_type i) const; 1000b57cec5SDimitry Andric reference at(size_type i); 1010b57cec5SDimitry Andric const_reference at(size_type i) const; 1020b57cec5SDimitry Andric reference front(); 1030b57cec5SDimitry Andric const_reference front() const; 1040b57cec5SDimitry Andric reference back(); 1050b57cec5SDimitry Andric const_reference back() const; 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric // modifiers: 1080b57cec5SDimitry Andric void push_front(const value_type& v); 1090b57cec5SDimitry Andric void push_front(value_type&& v); 1100b57cec5SDimitry Andric void push_back(const value_type& v); 1110b57cec5SDimitry Andric void push_back(value_type&& v); 1120b57cec5SDimitry Andric template <class... Args> reference emplace_front(Args&&... args); // reference in C++17 1130b57cec5SDimitry Andric template <class... Args> reference emplace_back(Args&&... args); // reference in C++17 1140b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator p, Args&&... args); 1150b57cec5SDimitry Andric iterator insert(const_iterator p, const value_type& v); 1160b57cec5SDimitry Andric iterator insert(const_iterator p, value_type&& v); 1170b57cec5SDimitry Andric iterator insert(const_iterator p, size_type n, const value_type& v); 1180b57cec5SDimitry Andric template <class InputIterator> 1190b57cec5SDimitry Andric iterator insert(const_iterator p, InputIterator f, InputIterator l); 1200b57cec5SDimitry Andric iterator insert(const_iterator p, initializer_list<value_type> il); 1210b57cec5SDimitry Andric void pop_front(); 1220b57cec5SDimitry Andric void pop_back(); 1230b57cec5SDimitry Andric iterator erase(const_iterator p); 1240b57cec5SDimitry Andric iterator erase(const_iterator f, const_iterator l); 1250b57cec5SDimitry Andric void swap(deque& c) 1260b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 1270b57cec5SDimitry Andric void clear() noexcept; 1280b57cec5SDimitry Andric}; 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 1310b57cec5SDimitry Andric deque(InputIterator, InputIterator, Allocator = Allocator()) 132*349cc55cSDimitry Andric -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andrictemplate <class T, class Allocator> 1350b57cec5SDimitry Andric bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1360b57cec5SDimitry Andrictemplate <class T, class Allocator> 1370b57cec5SDimitry Andric bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1380b57cec5SDimitry Andrictemplate <class T, class Allocator> 1390b57cec5SDimitry Andric bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1400b57cec5SDimitry Andrictemplate <class T, class Allocator> 1410b57cec5SDimitry Andric bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1420b57cec5SDimitry Andrictemplate <class T, class Allocator> 1430b57cec5SDimitry Andric bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1440b57cec5SDimitry Andrictemplate <class T, class Allocator> 1450b57cec5SDimitry Andric bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric// specialized algorithms: 1480b57cec5SDimitry Andrictemplate <class T, class Allocator> 1490b57cec5SDimitry Andric void swap(deque<T,Allocator>& x, deque<T,Allocator>& y) 1500b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andrictemplate <class T, class Allocator, class U> 1535ffd83dbSDimitry Andric typename deque<T, Allocator>::size_type 1545ffd83dbSDimitry Andric erase(deque<T, Allocator>& c, const U& value); // C++20 1550b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 1565ffd83dbSDimitry Andric typename deque<T, Allocator>::size_type 1575ffd83dbSDimitry Andric erase_if(deque<T, Allocator>& c, Predicate pred); // C++20 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric} // std 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric*/ 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric#include <__config> 164fe6060f1SDimitry Andric#include <__debug> 165*349cc55cSDimitry Andric#include <__iterator/iterator_traits.h> 1660b57cec5SDimitry Andric#include <__split_buffer> 167fe6060f1SDimitry Andric#include <__utility/forward.h> 168fe6060f1SDimitry Andric#include <algorithm> 169fe6060f1SDimitry Andric#include <compare> 1700b57cec5SDimitry Andric#include <initializer_list> 1710b57cec5SDimitry Andric#include <iterator> 172fe6060f1SDimitry Andric#include <limits> 1730b57cec5SDimitry Andric#include <stdexcept> 174fe6060f1SDimitry Andric#include <type_traits> 1750b57cec5SDimitry Andric#include <version> 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1780b57cec5SDimitry Andric#pragma GCC system_header 1790b57cec5SDimitry Andric#endif 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1820b57cec5SDimitry Andric#include <__undef_macros> 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> class __deque_base; 1880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque; 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andrictemplate <class _ValueType, class _Pointer, class _Reference, class _MapPointer, 1910b57cec5SDimitry Andric class _DiffType, _DiffType _BlockSize> 1920b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __deque_iterator; 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andrictemplate <class _RAIter, 1950b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 1960b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 1970b57cec5SDimitry Andriccopy(_RAIter __f, 1980b57cec5SDimitry Andric _RAIter __l, 1990b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 200480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2030b57cec5SDimitry Andric class _OutputIterator> 2040b57cec5SDimitry Andric_OutputIterator 2050b57cec5SDimitry Andriccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2060b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2070b57cec5SDimitry Andric _OutputIterator __r); 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2100b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2110b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2120b57cec5SDimitry Andriccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2130b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2140b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andrictemplate <class _RAIter, 2170b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2180b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2190b57cec5SDimitry Andriccopy_backward(_RAIter __f, 2200b57cec5SDimitry Andric _RAIter __l, 2210b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 222480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2250b57cec5SDimitry Andric class _OutputIterator> 2260b57cec5SDimitry Andric_OutputIterator 2270b57cec5SDimitry Andriccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2280b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2290b57cec5SDimitry Andric _OutputIterator __r); 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2320b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2330b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2340b57cec5SDimitry Andriccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2350b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2360b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andrictemplate <class _RAIter, 2390b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2400b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2410b57cec5SDimitry Andricmove(_RAIter __f, 2420b57cec5SDimitry Andric _RAIter __l, 2430b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 244480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); 2450b57cec5SDimitry Andric 2460b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2470b57cec5SDimitry Andric class _OutputIterator> 2480b57cec5SDimitry Andric_OutputIterator 2490b57cec5SDimitry Andricmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2500b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2510b57cec5SDimitry Andric _OutputIterator __r); 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2540b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2550b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2560b57cec5SDimitry Andricmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2570b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2580b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andrictemplate <class _RAIter, 2610b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2620b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2630b57cec5SDimitry Andricmove_backward(_RAIter __f, 2640b57cec5SDimitry Andric _RAIter __l, 2650b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 266480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); 2670b57cec5SDimitry Andric 2680b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2690b57cec5SDimitry Andric class _OutputIterator> 2700b57cec5SDimitry Andric_OutputIterator 2710b57cec5SDimitry Andricmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2720b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2730b57cec5SDimitry Andric _OutputIterator __r); 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2760b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2770b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2780b57cec5SDimitry Andricmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2790b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2800b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2810b57cec5SDimitry Andric 2820b57cec5SDimitry Andrictemplate <class _ValueType, class _DiffType> 2830b57cec5SDimitry Andricstruct __deque_block_size { 2840b57cec5SDimitry Andric static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16; 2850b57cec5SDimitry Andric}; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andrictemplate <class _ValueType, class _Pointer, class _Reference, class _MapPointer, 2880b57cec5SDimitry Andric class _DiffType, _DiffType _BS = 2890b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 2900b57cec5SDimitry Andric// Keep template parameter to avoid changing all template declarations thoughout 2910b57cec5SDimitry Andric// this file. 2920b57cec5SDimitry Andric 0 2930b57cec5SDimitry Andric#else 2940b57cec5SDimitry Andric __deque_block_size<_ValueType, _DiffType>::value 2950b57cec5SDimitry Andric#endif 2960b57cec5SDimitry Andric > 2970b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __deque_iterator 2980b57cec5SDimitry Andric{ 2990b57cec5SDimitry Andric typedef _MapPointer __map_iterator; 3000b57cec5SDimitry Andricpublic: 3010b57cec5SDimitry Andric typedef _Pointer pointer; 3020b57cec5SDimitry Andric typedef _DiffType difference_type; 3030b57cec5SDimitry Andricprivate: 3040b57cec5SDimitry Andric __map_iterator __m_iter_; 3050b57cec5SDimitry Andric pointer __ptr_; 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric static const difference_type __block_size; 3080b57cec5SDimitry Andricpublic: 3090b57cec5SDimitry Andric typedef _ValueType value_type; 3100b57cec5SDimitry Andric typedef random_access_iterator_tag iterator_category; 3110b57cec5SDimitry Andric typedef _Reference reference; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT 3140b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 3150b57cec5SDimitry Andric : __m_iter_(nullptr), __ptr_(nullptr) 3160b57cec5SDimitry Andric#endif 3170b57cec5SDimitry Andric {} 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric template <class _Pp, class _Rp, class _MP> 3200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3210b57cec5SDimitry Andric __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, 3220b57cec5SDimitry Andric typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT 3230b57cec5SDimitry Andric : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} 3260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() 3290b57cec5SDimitry Andric { 3300b57cec5SDimitry Andric if (++__ptr_ - *__m_iter_ == __block_size) 3310b57cec5SDimitry Andric { 3320b57cec5SDimitry Andric ++__m_iter_; 3330b57cec5SDimitry Andric __ptr_ = *__m_iter_; 3340b57cec5SDimitry Andric } 3350b57cec5SDimitry Andric return *this; 3360b57cec5SDimitry Andric } 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) 3390b57cec5SDimitry Andric { 3400b57cec5SDimitry Andric __deque_iterator __tmp = *this; 3410b57cec5SDimitry Andric ++(*this); 3420b57cec5SDimitry Andric return __tmp; 3430b57cec5SDimitry Andric } 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() 3460b57cec5SDimitry Andric { 3470b57cec5SDimitry Andric if (__ptr_ == *__m_iter_) 3480b57cec5SDimitry Andric { 3490b57cec5SDimitry Andric --__m_iter_; 3500b57cec5SDimitry Andric __ptr_ = *__m_iter_ + __block_size; 3510b57cec5SDimitry Andric } 3520b57cec5SDimitry Andric --__ptr_; 3530b57cec5SDimitry Andric return *this; 3540b57cec5SDimitry Andric } 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) 3570b57cec5SDimitry Andric { 3580b57cec5SDimitry Andric __deque_iterator __tmp = *this; 3590b57cec5SDimitry Andric --(*this); 3600b57cec5SDimitry Andric return __tmp; 3610b57cec5SDimitry Andric } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) 3640b57cec5SDimitry Andric { 3650b57cec5SDimitry Andric if (__n != 0) 3660b57cec5SDimitry Andric { 3670b57cec5SDimitry Andric __n += __ptr_ - *__m_iter_; 3680b57cec5SDimitry Andric if (__n > 0) 3690b57cec5SDimitry Andric { 3700b57cec5SDimitry Andric __m_iter_ += __n / __block_size; 3710b57cec5SDimitry Andric __ptr_ = *__m_iter_ + __n % __block_size; 3720b57cec5SDimitry Andric } 3730b57cec5SDimitry Andric else // (__n < 0) 3740b57cec5SDimitry Andric { 3750b57cec5SDimitry Andric difference_type __z = __block_size - 1 - __n; 3760b57cec5SDimitry Andric __m_iter_ -= __z / __block_size; 3770b57cec5SDimitry Andric __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); 3780b57cec5SDimitry Andric } 3790b57cec5SDimitry Andric } 3800b57cec5SDimitry Andric return *this; 3810b57cec5SDimitry Andric } 3820b57cec5SDimitry Andric 3830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) 3840b57cec5SDimitry Andric { 3850b57cec5SDimitry Andric return *this += -__n; 3860b57cec5SDimitry Andric } 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const 3890b57cec5SDimitry Andric { 3900b57cec5SDimitry Andric __deque_iterator __t(*this); 3910b57cec5SDimitry Andric __t += __n; 3920b57cec5SDimitry Andric return __t; 3930b57cec5SDimitry Andric } 3940b57cec5SDimitry Andric 3950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const 3960b57cec5SDimitry Andric { 3970b57cec5SDimitry Andric __deque_iterator __t(*this); 3980b57cec5SDimitry Andric __t -= __n; 3990b57cec5SDimitry Andric return __t; 4000b57cec5SDimitry Andric } 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4030b57cec5SDimitry Andric friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) 4040b57cec5SDimitry Andric {return __it + __n;} 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4070b57cec5SDimitry Andric friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) 4080b57cec5SDimitry Andric { 4090b57cec5SDimitry Andric if (__x != __y) 4100b57cec5SDimitry Andric return (__x.__m_iter_ - __y.__m_iter_) * __block_size 4110b57cec5SDimitry Andric + (__x.__ptr_ - *__x.__m_iter_) 4120b57cec5SDimitry Andric - (__y.__ptr_ - *__y.__m_iter_); 4130b57cec5SDimitry Andric return 0; 4140b57cec5SDimitry Andric } 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const 4170b57cec5SDimitry Andric {return *(*this + __n);} 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4200b57cec5SDimitry Andric bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) 4210b57cec5SDimitry Andric {return __x.__ptr_ == __y.__ptr_;} 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4240b57cec5SDimitry Andric bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) 4250b57cec5SDimitry Andric {return !(__x == __y);} 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4280b57cec5SDimitry Andric bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) 4290b57cec5SDimitry Andric {return __x.__m_iter_ < __y.__m_iter_ || 4300b57cec5SDimitry Andric (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} 4310b57cec5SDimitry Andric 4320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4330b57cec5SDimitry Andric bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) 4340b57cec5SDimitry Andric {return __y < __x;} 4350b57cec5SDimitry Andric 4360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4370b57cec5SDimitry Andric bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) 4380b57cec5SDimitry Andric {return !(__y < __x);} 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY friend 4410b57cec5SDimitry Andric bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) 4420b57cec5SDimitry Andric {return !(__x < __y);} 4430b57cec5SDimitry Andric 4440b57cec5SDimitry Andricprivate: 4450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT 4460b57cec5SDimitry Andric : __m_iter_(__m), __ptr_(__p) {} 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric template <class _Tp, class _Ap> friend class __deque_base; 4490b57cec5SDimitry Andric template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque; 4500b57cec5SDimitry Andric template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> 4510b57cec5SDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric template <class _RAIter, 4540b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4550b57cec5SDimitry Andric friend 4560b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4570b57cec5SDimitry Andric copy(_RAIter __f, 4580b57cec5SDimitry Andric _RAIter __l, 4590b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 460480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4630b57cec5SDimitry Andric class _OutputIterator> 4640b57cec5SDimitry Andric friend 4650b57cec5SDimitry Andric _OutputIterator 4660b57cec5SDimitry Andric copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4670b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4680b57cec5SDimitry Andric _OutputIterator __r); 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4710b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4720b57cec5SDimitry Andric friend 4730b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4740b57cec5SDimitry Andric copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4750b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4760b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 4770b57cec5SDimitry Andric 4780b57cec5SDimitry Andric template <class _RAIter, 4790b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4800b57cec5SDimitry Andric friend 4810b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4820b57cec5SDimitry Andric copy_backward(_RAIter __f, 4830b57cec5SDimitry Andric _RAIter __l, 4840b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 485480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); 4860b57cec5SDimitry Andric 4870b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4880b57cec5SDimitry Andric class _OutputIterator> 4890b57cec5SDimitry Andric friend 4900b57cec5SDimitry Andric _OutputIterator 4910b57cec5SDimitry Andric copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4920b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4930b57cec5SDimitry Andric _OutputIterator __r); 4940b57cec5SDimitry Andric 4950b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4960b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4970b57cec5SDimitry Andric friend 4980b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4990b57cec5SDimitry Andric copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5000b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5010b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 5020b57cec5SDimitry Andric 5030b57cec5SDimitry Andric template <class _RAIter, 5040b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5050b57cec5SDimitry Andric friend 5060b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5070b57cec5SDimitry Andric move(_RAIter __f, 5080b57cec5SDimitry Andric _RAIter __l, 5090b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 510480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); 5110b57cec5SDimitry Andric 5120b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5130b57cec5SDimitry Andric class _OutputIterator> 5140b57cec5SDimitry Andric friend 5150b57cec5SDimitry Andric _OutputIterator 5160b57cec5SDimitry Andric move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5170b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5180b57cec5SDimitry Andric _OutputIterator __r); 5190b57cec5SDimitry Andric 5200b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5210b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5220b57cec5SDimitry Andric friend 5230b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5240b57cec5SDimitry Andric move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5250b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5260b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andric template <class _RAIter, 5290b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5300b57cec5SDimitry Andric friend 5310b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5320b57cec5SDimitry Andric move_backward(_RAIter __f, 5330b57cec5SDimitry Andric _RAIter __l, 5340b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 535480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); 5360b57cec5SDimitry Andric 5370b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5380b57cec5SDimitry Andric class _OutputIterator> 5390b57cec5SDimitry Andric friend 5400b57cec5SDimitry Andric _OutputIterator 5410b57cec5SDimitry Andric move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5420b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5430b57cec5SDimitry Andric _OutputIterator __r); 5440b57cec5SDimitry Andric 5450b57cec5SDimitry Andric template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5460b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5470b57cec5SDimitry Andric friend 5480b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5490b57cec5SDimitry Andric move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5500b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5510b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 5520b57cec5SDimitry Andric}; 5530b57cec5SDimitry Andric 5540b57cec5SDimitry Andrictemplate <class _ValueType, class _Pointer, class _Reference, class _MapPointer, 5550b57cec5SDimitry Andric class _DiffType, _DiffType _BlockSize> 5560b57cec5SDimitry Andricconst _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, 5570b57cec5SDimitry Andric _DiffType, _BlockSize>::__block_size = 5580b57cec5SDimitry Andric __deque_block_size<_ValueType, _DiffType>::value; 5590b57cec5SDimitry Andric 5600b57cec5SDimitry Andric// copy 5610b57cec5SDimitry Andric 5620b57cec5SDimitry Andrictemplate <class _RAIter, 5630b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5640b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5650b57cec5SDimitry Andriccopy(_RAIter __f, 5660b57cec5SDimitry Andric _RAIter __l, 5670b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 568480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) 5690b57cec5SDimitry Andric{ 5700b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 5710b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 5720b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; 5730b57cec5SDimitry Andric while (__f != __l) 5740b57cec5SDimitry Andric { 5750b57cec5SDimitry Andric pointer __rb = __r.__ptr_; 5760b57cec5SDimitry Andric pointer __re = *__r.__m_iter_ + __block_size; 5770b57cec5SDimitry Andric difference_type __bs = __re - __rb; 5780b57cec5SDimitry Andric difference_type __n = __l - __f; 5790b57cec5SDimitry Andric _RAIter __m = __l; 5800b57cec5SDimitry Andric if (__n > __bs) 5810b57cec5SDimitry Andric { 5820b57cec5SDimitry Andric __n = __bs; 5830b57cec5SDimitry Andric __m = __f + __n; 5840b57cec5SDimitry Andric } 5850b57cec5SDimitry Andric _VSTD::copy(__f, __m, __rb); 5860b57cec5SDimitry Andric __f = __m; 5870b57cec5SDimitry Andric __r += __n; 5880b57cec5SDimitry Andric } 5890b57cec5SDimitry Andric return __r; 5900b57cec5SDimitry Andric} 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5930b57cec5SDimitry Andric class _OutputIterator> 5940b57cec5SDimitry Andric_OutputIterator 5950b57cec5SDimitry Andriccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5960b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5970b57cec5SDimitry Andric _OutputIterator __r) 5980b57cec5SDimitry Andric{ 5990b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 6000b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 6010b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; 6020b57cec5SDimitry Andric difference_type __n = __l - __f; 6030b57cec5SDimitry Andric while (__n > 0) 6040b57cec5SDimitry Andric { 6050b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 6060b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __block_size; 6070b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 6080b57cec5SDimitry Andric if (__bs > __n) 6090b57cec5SDimitry Andric { 6100b57cec5SDimitry Andric __bs = __n; 6110b57cec5SDimitry Andric __fe = __fb + __bs; 6120b57cec5SDimitry Andric } 6130b57cec5SDimitry Andric __r = _VSTD::copy(__fb, __fe, __r); 6140b57cec5SDimitry Andric __n -= __bs; 6150b57cec5SDimitry Andric __f += __bs; 6160b57cec5SDimitry Andric } 6170b57cec5SDimitry Andric return __r; 6180b57cec5SDimitry Andric} 6190b57cec5SDimitry Andric 6200b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 6210b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 6220b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 6230b57cec5SDimitry Andriccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 6240b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 6250b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 6260b57cec5SDimitry Andric{ 6270b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 6280b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 6290b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; 6300b57cec5SDimitry Andric difference_type __n = __l - __f; 6310b57cec5SDimitry Andric while (__n > 0) 6320b57cec5SDimitry Andric { 6330b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 6340b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __block_size; 6350b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 6360b57cec5SDimitry Andric if (__bs > __n) 6370b57cec5SDimitry Andric { 6380b57cec5SDimitry Andric __bs = __n; 6390b57cec5SDimitry Andric __fe = __fb + __bs; 6400b57cec5SDimitry Andric } 6410b57cec5SDimitry Andric __r = _VSTD::copy(__fb, __fe, __r); 6420b57cec5SDimitry Andric __n -= __bs; 6430b57cec5SDimitry Andric __f += __bs; 6440b57cec5SDimitry Andric } 6450b57cec5SDimitry Andric return __r; 6460b57cec5SDimitry Andric} 6470b57cec5SDimitry Andric 6480b57cec5SDimitry Andric// copy_backward 6490b57cec5SDimitry Andric 6500b57cec5SDimitry Andrictemplate <class _RAIter, 6510b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 6520b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 6530b57cec5SDimitry Andriccopy_backward(_RAIter __f, 6540b57cec5SDimitry Andric _RAIter __l, 6550b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 656480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) 6570b57cec5SDimitry Andric{ 6580b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 6590b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 6600b57cec5SDimitry Andric while (__f != __l) 6610b57cec5SDimitry Andric { 6620b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); 6630b57cec5SDimitry Andric pointer __rb = *__rp.__m_iter_; 6640b57cec5SDimitry Andric pointer __re = __rp.__ptr_ + 1; 6650b57cec5SDimitry Andric difference_type __bs = __re - __rb; 6660b57cec5SDimitry Andric difference_type __n = __l - __f; 6670b57cec5SDimitry Andric _RAIter __m = __f; 6680b57cec5SDimitry Andric if (__n > __bs) 6690b57cec5SDimitry Andric { 6700b57cec5SDimitry Andric __n = __bs; 6710b57cec5SDimitry Andric __m = __l - __n; 6720b57cec5SDimitry Andric } 6730b57cec5SDimitry Andric _VSTD::copy_backward(__m, __l, __re); 6740b57cec5SDimitry Andric __l = __m; 6750b57cec5SDimitry Andric __r -= __n; 6760b57cec5SDimitry Andric } 6770b57cec5SDimitry Andric return __r; 6780b57cec5SDimitry Andric} 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 6810b57cec5SDimitry Andric class _OutputIterator> 6820b57cec5SDimitry Andric_OutputIterator 6830b57cec5SDimitry Andriccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 6840b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 6850b57cec5SDimitry Andric _OutputIterator __r) 6860b57cec5SDimitry Andric{ 6870b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 6880b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 6890b57cec5SDimitry Andric difference_type __n = __l - __f; 6900b57cec5SDimitry Andric while (__n > 0) 6910b57cec5SDimitry Andric { 6920b57cec5SDimitry Andric --__l; 6930b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 6940b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 6950b57cec5SDimitry Andric difference_type __bs = __le - __lb; 6960b57cec5SDimitry Andric if (__bs > __n) 6970b57cec5SDimitry Andric { 6980b57cec5SDimitry Andric __bs = __n; 6990b57cec5SDimitry Andric __lb = __le - __bs; 7000b57cec5SDimitry Andric } 7010b57cec5SDimitry Andric __r = _VSTD::copy_backward(__lb, __le, __r); 7020b57cec5SDimitry Andric __n -= __bs; 7030b57cec5SDimitry Andric __l -= __bs - 1; 7040b57cec5SDimitry Andric } 7050b57cec5SDimitry Andric return __r; 7060b57cec5SDimitry Andric} 7070b57cec5SDimitry Andric 7080b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 7090b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7100b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7110b57cec5SDimitry Andriccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 7120b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 7130b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 7140b57cec5SDimitry Andric{ 7150b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 7160b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 7170b57cec5SDimitry Andric difference_type __n = __l - __f; 7180b57cec5SDimitry Andric while (__n > 0) 7190b57cec5SDimitry Andric { 7200b57cec5SDimitry Andric --__l; 7210b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 7220b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 7230b57cec5SDimitry Andric difference_type __bs = __le - __lb; 7240b57cec5SDimitry Andric if (__bs > __n) 7250b57cec5SDimitry Andric { 7260b57cec5SDimitry Andric __bs = __n; 7270b57cec5SDimitry Andric __lb = __le - __bs; 7280b57cec5SDimitry Andric } 7290b57cec5SDimitry Andric __r = _VSTD::copy_backward(__lb, __le, __r); 7300b57cec5SDimitry Andric __n -= __bs; 7310b57cec5SDimitry Andric __l -= __bs - 1; 7320b57cec5SDimitry Andric } 7330b57cec5SDimitry Andric return __r; 7340b57cec5SDimitry Andric} 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andric// move 7370b57cec5SDimitry Andric 7380b57cec5SDimitry Andrictemplate <class _RAIter, 7390b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7400b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7410b57cec5SDimitry Andricmove(_RAIter __f, 7420b57cec5SDimitry Andric _RAIter __l, 7430b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 744480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) 7450b57cec5SDimitry Andric{ 7460b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 7470b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 7480b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; 7490b57cec5SDimitry Andric while (__f != __l) 7500b57cec5SDimitry Andric { 7510b57cec5SDimitry Andric pointer __rb = __r.__ptr_; 7520b57cec5SDimitry Andric pointer __re = *__r.__m_iter_ + __block_size; 7530b57cec5SDimitry Andric difference_type __bs = __re - __rb; 7540b57cec5SDimitry Andric difference_type __n = __l - __f; 7550b57cec5SDimitry Andric _RAIter __m = __l; 7560b57cec5SDimitry Andric if (__n > __bs) 7570b57cec5SDimitry Andric { 7580b57cec5SDimitry Andric __n = __bs; 7590b57cec5SDimitry Andric __m = __f + __n; 7600b57cec5SDimitry Andric } 7610b57cec5SDimitry Andric _VSTD::move(__f, __m, __rb); 7620b57cec5SDimitry Andric __f = __m; 7630b57cec5SDimitry Andric __r += __n; 7640b57cec5SDimitry Andric } 7650b57cec5SDimitry Andric return __r; 7660b57cec5SDimitry Andric} 7670b57cec5SDimitry Andric 7680b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 7690b57cec5SDimitry Andric class _OutputIterator> 7700b57cec5SDimitry Andric_OutputIterator 7710b57cec5SDimitry Andricmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 7720b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 7730b57cec5SDimitry Andric _OutputIterator __r) 7740b57cec5SDimitry Andric{ 7750b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 7760b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 7770b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; 7780b57cec5SDimitry Andric difference_type __n = __l - __f; 7790b57cec5SDimitry Andric while (__n > 0) 7800b57cec5SDimitry Andric { 7810b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 7820b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __block_size; 7830b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 7840b57cec5SDimitry Andric if (__bs > __n) 7850b57cec5SDimitry Andric { 7860b57cec5SDimitry Andric __bs = __n; 7870b57cec5SDimitry Andric __fe = __fb + __bs; 7880b57cec5SDimitry Andric } 7890b57cec5SDimitry Andric __r = _VSTD::move(__fb, __fe, __r); 7900b57cec5SDimitry Andric __n -= __bs; 7910b57cec5SDimitry Andric __f += __bs; 7920b57cec5SDimitry Andric } 7930b57cec5SDimitry Andric return __r; 7940b57cec5SDimitry Andric} 7950b57cec5SDimitry Andric 7960b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 7970b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7980b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7990b57cec5SDimitry Andricmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 8000b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 8010b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 8020b57cec5SDimitry Andric{ 8030b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 8040b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 8050b57cec5SDimitry Andric const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; 8060b57cec5SDimitry Andric difference_type __n = __l - __f; 8070b57cec5SDimitry Andric while (__n > 0) 8080b57cec5SDimitry Andric { 8090b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 8100b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __block_size; 8110b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 8120b57cec5SDimitry Andric if (__bs > __n) 8130b57cec5SDimitry Andric { 8140b57cec5SDimitry Andric __bs = __n; 8150b57cec5SDimitry Andric __fe = __fb + __bs; 8160b57cec5SDimitry Andric } 8170b57cec5SDimitry Andric __r = _VSTD::move(__fb, __fe, __r); 8180b57cec5SDimitry Andric __n -= __bs; 8190b57cec5SDimitry Andric __f += __bs; 8200b57cec5SDimitry Andric } 8210b57cec5SDimitry Andric return __r; 8220b57cec5SDimitry Andric} 8230b57cec5SDimitry Andric 8240b57cec5SDimitry Andric// move_backward 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andrictemplate <class _RAIter, 8270b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 8280b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 8290b57cec5SDimitry Andricmove_backward(_RAIter __f, 8300b57cec5SDimitry Andric _RAIter __l, 8310b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 832480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) 8330b57cec5SDimitry Andric{ 8340b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 8350b57cec5SDimitry Andric typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 8360b57cec5SDimitry Andric while (__f != __l) 8370b57cec5SDimitry Andric { 8380b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); 8390b57cec5SDimitry Andric pointer __rb = *__rp.__m_iter_; 8400b57cec5SDimitry Andric pointer __re = __rp.__ptr_ + 1; 8410b57cec5SDimitry Andric difference_type __bs = __re - __rb; 8420b57cec5SDimitry Andric difference_type __n = __l - __f; 8430b57cec5SDimitry Andric _RAIter __m = __f; 8440b57cec5SDimitry Andric if (__n > __bs) 8450b57cec5SDimitry Andric { 8460b57cec5SDimitry Andric __n = __bs; 8470b57cec5SDimitry Andric __m = __l - __n; 8480b57cec5SDimitry Andric } 8490b57cec5SDimitry Andric _VSTD::move_backward(__m, __l, __re); 8500b57cec5SDimitry Andric __l = __m; 8510b57cec5SDimitry Andric __r -= __n; 8520b57cec5SDimitry Andric } 8530b57cec5SDimitry Andric return __r; 8540b57cec5SDimitry Andric} 8550b57cec5SDimitry Andric 8560b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 8570b57cec5SDimitry Andric class _OutputIterator> 8580b57cec5SDimitry Andric_OutputIterator 8590b57cec5SDimitry Andricmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 8600b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 8610b57cec5SDimitry Andric _OutputIterator __r) 8620b57cec5SDimitry Andric{ 8630b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 8640b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 8650b57cec5SDimitry Andric difference_type __n = __l - __f; 8660b57cec5SDimitry Andric while (__n > 0) 8670b57cec5SDimitry Andric { 8680b57cec5SDimitry Andric --__l; 8690b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 8700b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 8710b57cec5SDimitry Andric difference_type __bs = __le - __lb; 8720b57cec5SDimitry Andric if (__bs > __n) 8730b57cec5SDimitry Andric { 8740b57cec5SDimitry Andric __bs = __n; 8750b57cec5SDimitry Andric __lb = __le - __bs; 8760b57cec5SDimitry Andric } 8770b57cec5SDimitry Andric __r = _VSTD::move_backward(__lb, __le, __r); 8780b57cec5SDimitry Andric __n -= __bs; 8790b57cec5SDimitry Andric __l -= __bs - 1; 8800b57cec5SDimitry Andric } 8810b57cec5SDimitry Andric return __r; 8820b57cec5SDimitry Andric} 8830b57cec5SDimitry Andric 8840b57cec5SDimitry Andrictemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 8850b57cec5SDimitry Andric class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 8860b57cec5SDimitry Andric__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 8870b57cec5SDimitry Andricmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 8880b57cec5SDimitry Andric __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 8890b57cec5SDimitry Andric __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 8900b57cec5SDimitry Andric{ 8910b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 8920b57cec5SDimitry Andric typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 8930b57cec5SDimitry Andric difference_type __n = __l - __f; 8940b57cec5SDimitry Andric while (__n > 0) 8950b57cec5SDimitry Andric { 8960b57cec5SDimitry Andric --__l; 8970b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 8980b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 8990b57cec5SDimitry Andric difference_type __bs = __le - __lb; 9000b57cec5SDimitry Andric if (__bs > __n) 9010b57cec5SDimitry Andric { 9020b57cec5SDimitry Andric __bs = __n; 9030b57cec5SDimitry Andric __lb = __le - __bs; 9040b57cec5SDimitry Andric } 9050b57cec5SDimitry Andric __r = _VSTD::move_backward(__lb, __le, __r); 9060b57cec5SDimitry Andric __n -= __bs; 9070b57cec5SDimitry Andric __l -= __bs - 1; 9080b57cec5SDimitry Andric } 9090b57cec5SDimitry Andric return __r; 9100b57cec5SDimitry Andric} 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9130b57cec5SDimitry Andricclass __deque_base 9140b57cec5SDimitry Andric{ 9150b57cec5SDimitry Andric __deque_base(const __deque_base& __c); 9160b57cec5SDimitry Andric __deque_base& operator=(const __deque_base& __c); 9170b57cec5SDimitry Andricpublic: 9180b57cec5SDimitry Andric typedef _Allocator allocator_type; 9190b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 9200b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 921e40139ffSDimitry Andric 9220b57cec5SDimitry Andric typedef _Tp value_type; 9230b57cec5SDimitry Andric typedef value_type& reference; 9240b57cec5SDimitry Andric typedef const value_type& const_reference; 9250b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 9260b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 9270b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 9280b57cec5SDimitry Andric 9290b57cec5SDimitry Andric static const difference_type __block_size; 9300b57cec5SDimitry Andric 9310b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; 9320b57cec5SDimitry Andric typedef allocator_traits<__pointer_allocator> __map_traits; 9330b57cec5SDimitry Andric typedef typename __map_traits::pointer __map_pointer; 9340b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; 9350b57cec5SDimitry Andric typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; 9360b57cec5SDimitry Andric typedef __split_buffer<pointer, __pointer_allocator> __map; 9370b57cec5SDimitry Andric 9380b57cec5SDimitry Andric typedef __deque_iterator<value_type, pointer, reference, __map_pointer, 9390b57cec5SDimitry Andric difference_type> iterator; 9400b57cec5SDimitry Andric typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, 9410b57cec5SDimitry Andric difference_type> const_iterator; 9420b57cec5SDimitry Andric 943e40139ffSDimitry Andric struct __deque_block_range { 944e40139ffSDimitry Andric explicit __deque_block_range(pointer __b, pointer __e) _NOEXCEPT : __begin_(__b), __end_(__e) {} 945e40139ffSDimitry Andric const pointer __begin_; 946e40139ffSDimitry Andric const pointer __end_; 947e40139ffSDimitry Andric }; 948e40139ffSDimitry Andric 949e40139ffSDimitry Andric struct __deque_range { 950e40139ffSDimitry Andric iterator __pos_; 951e40139ffSDimitry Andric const iterator __end_; 952e40139ffSDimitry Andric 953e40139ffSDimitry Andric __deque_range(iterator __pos, iterator __e) _NOEXCEPT 954e40139ffSDimitry Andric : __pos_(__pos), __end_(__e) {} 955e40139ffSDimitry Andric 956e40139ffSDimitry Andric explicit operator bool() const _NOEXCEPT { 957e40139ffSDimitry Andric return __pos_ != __end_; 958e40139ffSDimitry Andric } 959e40139ffSDimitry Andric 960e40139ffSDimitry Andric __deque_range begin() const { 961e40139ffSDimitry Andric return *this; 962e40139ffSDimitry Andric } 963e40139ffSDimitry Andric 964e40139ffSDimitry Andric __deque_range end() const { 965e40139ffSDimitry Andric return __deque_range(__end_, __end_); 966e40139ffSDimitry Andric } 967e40139ffSDimitry Andric __deque_block_range operator*() const _NOEXCEPT { 968e40139ffSDimitry Andric if (__pos_.__m_iter_ == __end_.__m_iter_) { 969e40139ffSDimitry Andric return __deque_block_range(__pos_.__ptr_, __end_.__ptr_); 970e40139ffSDimitry Andric } 971e40139ffSDimitry Andric return __deque_block_range(__pos_.__ptr_, *__pos_.__m_iter_ + __block_size); 972e40139ffSDimitry Andric } 973e40139ffSDimitry Andric 974e40139ffSDimitry Andric __deque_range& operator++() _NOEXCEPT { 975e40139ffSDimitry Andric if (__pos_.__m_iter_ == __end_.__m_iter_) { 976e40139ffSDimitry Andric __pos_ = __end_; 977e40139ffSDimitry Andric } else { 978e40139ffSDimitry Andric ++__pos_.__m_iter_; 979e40139ffSDimitry Andric __pos_.__ptr_ = *__pos_.__m_iter_; 980e40139ffSDimitry Andric } 981e40139ffSDimitry Andric return *this; 982e40139ffSDimitry Andric } 983e40139ffSDimitry Andric 984e40139ffSDimitry Andric 985e40139ffSDimitry Andric friend bool operator==(__deque_range const& __lhs, __deque_range const& __rhs) { 986e40139ffSDimitry Andric return __lhs.__pos_ == __rhs.__pos_; 987e40139ffSDimitry Andric } 988e40139ffSDimitry Andric friend bool operator!=(__deque_range const& __lhs, __deque_range const& __rhs) { 989e40139ffSDimitry Andric return !(__lhs == __rhs); 990e40139ffSDimitry Andric } 991e40139ffSDimitry Andric }; 992e40139ffSDimitry Andric 993e40139ffSDimitry Andric 994e40139ffSDimitry Andric 995e40139ffSDimitry Andric struct _ConstructTransaction { 996e40139ffSDimitry Andric _ConstructTransaction(__deque_base* __db, __deque_block_range& __r) 997e40139ffSDimitry Andric : __pos_(__r.__begin_), __end_(__r.__end_), __begin_(__r.__begin_), __base_(__db) {} 998e40139ffSDimitry Andric 999e40139ffSDimitry Andric 1000e40139ffSDimitry Andric ~_ConstructTransaction() { 1001e40139ffSDimitry Andric __base_->size() += (__pos_ - __begin_); 1002e40139ffSDimitry Andric } 1003e40139ffSDimitry Andric 1004e40139ffSDimitry Andric pointer __pos_; 1005e40139ffSDimitry Andric const pointer __end_; 1006e40139ffSDimitry Andric private: 1007e40139ffSDimitry Andric const pointer __begin_; 1008e40139ffSDimitry Andric __deque_base * const __base_; 1009e40139ffSDimitry Andric }; 1010e40139ffSDimitry Andric 10110b57cec5SDimitry Andricprotected: 10120b57cec5SDimitry Andric __map __map_; 10130b57cec5SDimitry Andric size_type __start_; 10140b57cec5SDimitry Andric __compressed_pair<size_type, allocator_type> __size_; 10150b57cec5SDimitry Andric 10160b57cec5SDimitry Andric iterator begin() _NOEXCEPT; 10170b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT; 10180b57cec5SDimitry Andric iterator end() _NOEXCEPT; 10190b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT; 10200b57cec5SDimitry Andric 10210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} 10220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10230b57cec5SDimitry Andric const size_type& size() const _NOEXCEPT {return __size_.first();} 10240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} 10250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10260b57cec5SDimitry Andric const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} 10270b57cec5SDimitry Andric 10280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10290b57cec5SDimitry Andric __deque_base() 10300b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 10310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10320b57cec5SDimitry Andric explicit __deque_base(const allocator_type& __a); 10330b57cec5SDimitry Andricpublic: 10340b57cec5SDimitry Andric ~__deque_base(); 10350b57cec5SDimitry Andric 10360b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10370b57cec5SDimitry Andric __deque_base(__deque_base&& __c) 10380b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 10390b57cec5SDimitry Andric __deque_base(__deque_base&& __c, const allocator_type& __a); 10400b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 10410b57cec5SDimitry Andric 10420b57cec5SDimitry Andric void swap(__deque_base& __c) 10430b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 10440b57cec5SDimitry Andric _NOEXCEPT; 10450b57cec5SDimitry Andric#else 10460b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 10470b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 10480b57cec5SDimitry Andric#endif 10490b57cec5SDimitry Andricprotected: 10500b57cec5SDimitry Andric void clear() _NOEXCEPT; 10510b57cec5SDimitry Andric 10520b57cec5SDimitry Andric bool __invariants() const; 10530b57cec5SDimitry Andric 10540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10550b57cec5SDimitry Andric void __move_assign(__deque_base& __c) 10560b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 10570b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 10580b57cec5SDimitry Andric { 10590b57cec5SDimitry Andric __map_ = _VSTD::move(__c.__map_); 10600b57cec5SDimitry Andric __start_ = __c.__start_; 10610b57cec5SDimitry Andric size() = __c.size(); 10620b57cec5SDimitry Andric __move_assign_alloc(__c); 10630b57cec5SDimitry Andric __c.__start_ = __c.size() = 0; 10640b57cec5SDimitry Andric } 10650b57cec5SDimitry Andric 10660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10670b57cec5SDimitry Andric void __move_assign_alloc(__deque_base& __c) 10680b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || 10690b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 10700b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 10710b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 10720b57cec5SDimitry Andric 10730b57cec5SDimitry Andricprivate: 10740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10750b57cec5SDimitry Andric void __move_assign_alloc(__deque_base& __c, true_type) 10760b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 10770b57cec5SDimitry Andric { 10780b57cec5SDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 10790b57cec5SDimitry Andric } 10800b57cec5SDimitry Andric 10810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10820b57cec5SDimitry Andric void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT 10830b57cec5SDimitry Andric {} 10840b57cec5SDimitry Andric}; 10850b57cec5SDimitry Andric 10860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10870b57cec5SDimitry Andricconst typename __deque_base<_Tp, _Allocator>::difference_type 10880b57cec5SDimitry Andric __deque_base<_Tp, _Allocator>::__block_size = 10890b57cec5SDimitry Andric __deque_block_size<value_type, difference_type>::value; 10900b57cec5SDimitry Andric 10910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10920b57cec5SDimitry Andricbool 10930b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::__invariants() const 10940b57cec5SDimitry Andric{ 10950b57cec5SDimitry Andric if (!__map_.__invariants()) 10960b57cec5SDimitry Andric return false; 10970b57cec5SDimitry Andric if (__map_.size() >= size_type(-1) / __block_size) 10980b57cec5SDimitry Andric return false; 10990b57cec5SDimitry Andric for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); 11000b57cec5SDimitry Andric __i != __e; ++__i) 11010b57cec5SDimitry Andric if (*__i == nullptr) 11020b57cec5SDimitry Andric return false; 11030b57cec5SDimitry Andric if (__map_.size() != 0) 11040b57cec5SDimitry Andric { 11050b57cec5SDimitry Andric if (size() >= __map_.size() * __block_size) 11060b57cec5SDimitry Andric return false; 11070b57cec5SDimitry Andric if (__start_ >= __map_.size() * __block_size - size()) 11080b57cec5SDimitry Andric return false; 11090b57cec5SDimitry Andric } 11100b57cec5SDimitry Andric else 11110b57cec5SDimitry Andric { 11120b57cec5SDimitry Andric if (size() != 0) 11130b57cec5SDimitry Andric return false; 11140b57cec5SDimitry Andric if (__start_ != 0) 11150b57cec5SDimitry Andric return false; 11160b57cec5SDimitry Andric } 11170b57cec5SDimitry Andric return true; 11180b57cec5SDimitry Andric} 11190b57cec5SDimitry Andric 11200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11210b57cec5SDimitry Andrictypename __deque_base<_Tp, _Allocator>::iterator 11220b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT 11230b57cec5SDimitry Andric{ 11240b57cec5SDimitry Andric __map_pointer __mp = __map_.begin() + __start_ / __block_size; 11250b57cec5SDimitry Andric return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); 11260b57cec5SDimitry Andric} 11270b57cec5SDimitry Andric 11280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11290b57cec5SDimitry Andrictypename __deque_base<_Tp, _Allocator>::const_iterator 11300b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT 11310b57cec5SDimitry Andric{ 11320b57cec5SDimitry Andric __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); 11330b57cec5SDimitry Andric return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); 11340b57cec5SDimitry Andric} 11350b57cec5SDimitry Andric 11360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11370b57cec5SDimitry Andrictypename __deque_base<_Tp, _Allocator>::iterator 11380b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::end() _NOEXCEPT 11390b57cec5SDimitry Andric{ 11400b57cec5SDimitry Andric size_type __p = size() + __start_; 11410b57cec5SDimitry Andric __map_pointer __mp = __map_.begin() + __p / __block_size; 11420b57cec5SDimitry Andric return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); 11430b57cec5SDimitry Andric} 11440b57cec5SDimitry Andric 11450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11460b57cec5SDimitry Andrictypename __deque_base<_Tp, _Allocator>::const_iterator 11470b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT 11480b57cec5SDimitry Andric{ 11490b57cec5SDimitry Andric size_type __p = size() + __start_; 11500b57cec5SDimitry Andric __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); 11510b57cec5SDimitry Andric return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); 11520b57cec5SDimitry Andric} 11530b57cec5SDimitry Andric 11540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11550b57cec5SDimitry Andricinline 11560b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::__deque_base() 11570b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 1158480093f4SDimitry Andric : __start_(0), __size_(0, __default_init_tag()) {} 11590b57cec5SDimitry Andric 11600b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11610b57cec5SDimitry Andricinline 11620b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) 11630b57cec5SDimitry Andric : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} 11640b57cec5SDimitry Andric 11650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11660b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::~__deque_base() 11670b57cec5SDimitry Andric{ 11680b57cec5SDimitry Andric clear(); 11690b57cec5SDimitry Andric typename __map::iterator __i = __map_.begin(); 11700b57cec5SDimitry Andric typename __map::iterator __e = __map_.end(); 11710b57cec5SDimitry Andric for (; __i != __e; ++__i) 11720b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), *__i, __block_size); 11730b57cec5SDimitry Andric} 11740b57cec5SDimitry Andric 11750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 11760b57cec5SDimitry Andric 11770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11780b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) 11790b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 11800b57cec5SDimitry Andric : __map_(_VSTD::move(__c.__map_)), 11810b57cec5SDimitry Andric __start_(_VSTD::move(__c.__start_)), 11820b57cec5SDimitry Andric __size_(_VSTD::move(__c.__size_)) 11830b57cec5SDimitry Andric{ 11840b57cec5SDimitry Andric __c.__start_ = 0; 11850b57cec5SDimitry Andric __c.size() = 0; 11860b57cec5SDimitry Andric} 11870b57cec5SDimitry Andric 11880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11890b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) 11900b57cec5SDimitry Andric : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), 11910b57cec5SDimitry Andric __start_(_VSTD::move(__c.__start_)), 11920b57cec5SDimitry Andric __size_(_VSTD::move(__c.size()), __a) 11930b57cec5SDimitry Andric{ 11940b57cec5SDimitry Andric if (__a == __c.__alloc()) 11950b57cec5SDimitry Andric { 11960b57cec5SDimitry Andric __c.__start_ = 0; 11970b57cec5SDimitry Andric __c.size() = 0; 11980b57cec5SDimitry Andric } 11990b57cec5SDimitry Andric else 12000b57cec5SDimitry Andric { 12010b57cec5SDimitry Andric __map_.clear(); 12020b57cec5SDimitry Andric __start_ = 0; 12030b57cec5SDimitry Andric size() = 0; 12040b57cec5SDimitry Andric } 12050b57cec5SDimitry Andric} 12060b57cec5SDimitry Andric 12070b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 12080b57cec5SDimitry Andric 12090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12100b57cec5SDimitry Andricvoid 12110b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::swap(__deque_base& __c) 12120b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 12130b57cec5SDimitry Andric _NOEXCEPT 12140b57cec5SDimitry Andric#else 12150b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 12160b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 12170b57cec5SDimitry Andric#endif 12180b57cec5SDimitry Andric{ 12190b57cec5SDimitry Andric __map_.swap(__c.__map_); 12200b57cec5SDimitry Andric _VSTD::swap(__start_, __c.__start_); 12210b57cec5SDimitry Andric _VSTD::swap(size(), __c.size()); 1222e8d8bef9SDimitry Andric _VSTD::__swap_allocator(__alloc(), __c.__alloc()); 12230b57cec5SDimitry Andric} 12240b57cec5SDimitry Andric 12250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12260b57cec5SDimitry Andricvoid 12270b57cec5SDimitry Andric__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT 12280b57cec5SDimitry Andric{ 12290b57cec5SDimitry Andric allocator_type& __a = __alloc(); 12300b57cec5SDimitry Andric for (iterator __i = begin(), __e = end(); __i != __e; ++__i) 12310b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 12320b57cec5SDimitry Andric size() = 0; 12330b57cec5SDimitry Andric while (__map_.size() > 2) 12340b57cec5SDimitry Andric { 12350b57cec5SDimitry Andric __alloc_traits::deallocate(__a, __map_.front(), __block_size); 12360b57cec5SDimitry Andric __map_.pop_front(); 12370b57cec5SDimitry Andric } 12380b57cec5SDimitry Andric switch (__map_.size()) 12390b57cec5SDimitry Andric { 12400b57cec5SDimitry Andric case 1: 12410b57cec5SDimitry Andric __start_ = __block_size / 2; 12420b57cec5SDimitry Andric break; 12430b57cec5SDimitry Andric case 2: 12440b57cec5SDimitry Andric __start_ = __block_size; 12450b57cec5SDimitry Andric break; 12460b57cec5SDimitry Andric } 12470b57cec5SDimitry Andric} 12480b57cec5SDimitry Andric 12490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /*= allocator<_Tp>*/> 12500b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS deque 12510b57cec5SDimitry Andric : private __deque_base<_Tp, _Allocator> 12520b57cec5SDimitry Andric{ 12530b57cec5SDimitry Andricpublic: 12540b57cec5SDimitry Andric // types: 12550b57cec5SDimitry Andric 12560b57cec5SDimitry Andric typedef _Tp value_type; 12570b57cec5SDimitry Andric typedef _Allocator allocator_type; 12580b57cec5SDimitry Andric 12590b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 12600b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 12610b57cec5SDimitry Andric 12620b57cec5SDimitry Andric typedef __deque_base<value_type, allocator_type> __base; 12630b57cec5SDimitry Andric 12640b57cec5SDimitry Andric typedef typename __base::__alloc_traits __alloc_traits; 12650b57cec5SDimitry Andric typedef typename __base::reference reference; 12660b57cec5SDimitry Andric typedef typename __base::const_reference const_reference; 12670b57cec5SDimitry Andric typedef typename __base::iterator iterator; 12680b57cec5SDimitry Andric typedef typename __base::const_iterator const_iterator; 1269*349cc55cSDimitry Andric typedef typename __allocator_traits<allocator_type>::size_type size_type; 12700b57cec5SDimitry Andric typedef typename __base::difference_type difference_type; 12710b57cec5SDimitry Andric 12720b57cec5SDimitry Andric typedef typename __base::pointer pointer; 12730b57cec5SDimitry Andric typedef typename __base::const_pointer const_pointer; 12740b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 12750b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 12760b57cec5SDimitry Andric 1277e40139ffSDimitry Andric using typename __base::__deque_range; 1278e40139ffSDimitry Andric using typename __base::__deque_block_range; 1279e40139ffSDimitry Andric using typename __base::_ConstructTransaction; 1280e40139ffSDimitry Andric 12810b57cec5SDimitry Andric // construct/copy/destroy: 12820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12830b57cec5SDimitry Andric deque() 12840b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 12850b57cec5SDimitry Andric {} 12860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} 12870b57cec5SDimitry Andric explicit deque(size_type __n); 12880b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 12890b57cec5SDimitry Andric explicit deque(size_type __n, const _Allocator& __a); 12900b57cec5SDimitry Andric#endif 12910b57cec5SDimitry Andric deque(size_type __n, const value_type& __v); 12920b57cec5SDimitry Andric deque(size_type __n, const value_type& __v, const allocator_type& __a); 12930b57cec5SDimitry Andric template <class _InputIter> 12940b57cec5SDimitry Andric deque(_InputIter __f, _InputIter __l, 1295480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); 12960b57cec5SDimitry Andric template <class _InputIter> 12970b57cec5SDimitry Andric deque(_InputIter __f, _InputIter __l, const allocator_type& __a, 1298480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); 12990b57cec5SDimitry Andric deque(const deque& __c); 1300fe6060f1SDimitry Andric deque(const deque& __c, const __identity_t<allocator_type>& __a); 13010b57cec5SDimitry Andric 13020b57cec5SDimitry Andric deque& operator=(const deque& __c); 13030b57cec5SDimitry Andric 13040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 13050b57cec5SDimitry Andric deque(initializer_list<value_type> __il); 13060b57cec5SDimitry Andric deque(initializer_list<value_type> __il, const allocator_type& __a); 13070b57cec5SDimitry Andric 13080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13090b57cec5SDimitry Andric deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} 13100b57cec5SDimitry Andric 13110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13120b57cec5SDimitry Andric deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); 13130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1314fe6060f1SDimitry Andric deque(deque&& __c, const __identity_t<allocator_type>& __a); 13150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13160b57cec5SDimitry Andric deque& operator=(deque&& __c) 13170b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 13180b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value); 13190b57cec5SDimitry Andric 13200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13210b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} 13220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 13230b57cec5SDimitry Andric 13240b57cec5SDimitry Andric template <class _InputIter> 13250b57cec5SDimitry Andric void assign(_InputIter __f, _InputIter __l, 1326480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && 1327480093f4SDimitry Andric !__is_cpp17_random_access_iterator<_InputIter>::value>::type* = 0); 13280b57cec5SDimitry Andric template <class _RAIter> 13290b57cec5SDimitry Andric void assign(_RAIter __f, _RAIter __l, 1330480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); 13310b57cec5SDimitry Andric void assign(size_type __n, const value_type& __v); 13320b57cec5SDimitry Andric 13330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13340b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT; 13350b57cec5SDimitry Andric 13360b57cec5SDimitry Andric // iterators: 13370b57cec5SDimitry Andric 13380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13390b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return __base::begin();} 13400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13410b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return __base::begin();} 13420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13430b57cec5SDimitry Andric iterator end() _NOEXCEPT {return __base::end();} 13440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13450b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return __base::end();} 13460b57cec5SDimitry Andric 13470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13480b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 13490b57cec5SDimitry Andric {return reverse_iterator(__base::end());} 13500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13510b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 13520b57cec5SDimitry Andric {return const_reverse_iterator(__base::end());} 13530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13540b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 13550b57cec5SDimitry Andric {return reverse_iterator(__base::begin());} 13560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13570b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 13580b57cec5SDimitry Andric {return const_reverse_iterator(__base::begin());} 13590b57cec5SDimitry Andric 13600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13610b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 13620b57cec5SDimitry Andric {return __base::begin();} 13630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13640b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 13650b57cec5SDimitry Andric {return __base::end();} 13660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13670b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 13680b57cec5SDimitry Andric {return const_reverse_iterator(__base::end());} 13690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13700b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 13710b57cec5SDimitry Andric {return const_reverse_iterator(__base::begin());} 13720b57cec5SDimitry Andric 13730b57cec5SDimitry Andric // capacity: 13740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13750b57cec5SDimitry Andric size_type size() const _NOEXCEPT {return __base::size();} 13760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13770b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT 1378e8d8bef9SDimitry Andric {return _VSTD::min<size_type>( 13790b57cec5SDimitry Andric __alloc_traits::max_size(__base::__alloc()), 13800b57cec5SDimitry Andric numeric_limits<difference_type>::max());} 13810b57cec5SDimitry Andric void resize(size_type __n); 13820b57cec5SDimitry Andric void resize(size_type __n, const value_type& __v); 13830b57cec5SDimitry Andric void shrink_to_fit() _NOEXCEPT; 13840b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 13850b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return __base::size() == 0;} 13860b57cec5SDimitry Andric 13870b57cec5SDimitry Andric // element access: 13880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13890b57cec5SDimitry Andric reference operator[](size_type __i) _NOEXCEPT; 13900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13910b57cec5SDimitry Andric const_reference operator[](size_type __i) const _NOEXCEPT; 13920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13930b57cec5SDimitry Andric reference at(size_type __i); 13940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13950b57cec5SDimitry Andric const_reference at(size_type __i) const; 13960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13970b57cec5SDimitry Andric reference front() _NOEXCEPT; 13980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13990b57cec5SDimitry Andric const_reference front() const _NOEXCEPT; 14000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14010b57cec5SDimitry Andric reference back() _NOEXCEPT; 14020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14030b57cec5SDimitry Andric const_reference back() const _NOEXCEPT; 14040b57cec5SDimitry Andric 14050b57cec5SDimitry Andric // 23.2.2.3 modifiers: 14060b57cec5SDimitry Andric void push_front(const value_type& __v); 14070b57cec5SDimitry Andric void push_back(const value_type& __v); 14080b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 14090b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 14100b57cec5SDimitry Andric template <class... _Args> reference emplace_front(_Args&&... __args); 14110b57cec5SDimitry Andric template <class... _Args> reference emplace_back (_Args&&... __args); 14120b57cec5SDimitry Andric#else 14130b57cec5SDimitry Andric template <class... _Args> void emplace_front(_Args&&... __args); 14140b57cec5SDimitry Andric template <class... _Args> void emplace_back (_Args&&... __args); 14150b57cec5SDimitry Andric#endif 14160b57cec5SDimitry Andric template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); 14170b57cec5SDimitry Andric 14180b57cec5SDimitry Andric void push_front(value_type&& __v); 14190b57cec5SDimitry Andric void push_back(value_type&& __v); 14200b57cec5SDimitry Andric iterator insert(const_iterator __p, value_type&& __v); 14210b57cec5SDimitry Andric 14220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14230b57cec5SDimitry Andric iterator insert(const_iterator __p, initializer_list<value_type> __il) 14240b57cec5SDimitry Andric {return insert(__p, __il.begin(), __il.end());} 14250b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 14260b57cec5SDimitry Andric iterator insert(const_iterator __p, const value_type& __v); 14270b57cec5SDimitry Andric iterator insert(const_iterator __p, size_type __n, const value_type& __v); 14280b57cec5SDimitry Andric template <class _InputIter> 14290b57cec5SDimitry Andric iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, 1430480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value 1431480093f4SDimitry Andric &&!__is_cpp17_forward_iterator<_InputIter>::value>::type* = 0); 14320b57cec5SDimitry Andric template <class _ForwardIterator> 14330b57cec5SDimitry Andric iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, 1434480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value 1435480093f4SDimitry Andric &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); 14360b57cec5SDimitry Andric template <class _BiIter> 14370b57cec5SDimitry Andric iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, 1438480093f4SDimitry Andric typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type* = 0); 14390b57cec5SDimitry Andric 14400b57cec5SDimitry Andric void pop_front(); 14410b57cec5SDimitry Andric void pop_back(); 14420b57cec5SDimitry Andric iterator erase(const_iterator __p); 14430b57cec5SDimitry Andric iterator erase(const_iterator __f, const_iterator __l); 14440b57cec5SDimitry Andric 14450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14460b57cec5SDimitry Andric void swap(deque& __c) 14470b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 14480b57cec5SDimitry Andric _NOEXCEPT; 14490b57cec5SDimitry Andric#else 14500b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 14510b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 14520b57cec5SDimitry Andric#endif 14530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14540b57cec5SDimitry Andric void clear() _NOEXCEPT; 14550b57cec5SDimitry Andric 14560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14570b57cec5SDimitry Andric bool __invariants() const {return __base::__invariants();} 1458e40139ffSDimitry Andric 14590b57cec5SDimitry Andric typedef typename __base::__map_const_pointer __map_const_pointer; 14600b57cec5SDimitry Andric 14610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14620b57cec5SDimitry Andric static size_type __recommend_blocks(size_type __n) 14630b57cec5SDimitry Andric { 14640b57cec5SDimitry Andric return __n / __base::__block_size + (__n % __base::__block_size != 0); 14650b57cec5SDimitry Andric } 14660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14670b57cec5SDimitry Andric size_type __capacity() const 14680b57cec5SDimitry Andric { 14690b57cec5SDimitry Andric return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; 14700b57cec5SDimitry Andric } 14710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1472e40139ffSDimitry Andric size_type __block_count() const 1473e40139ffSDimitry Andric { 1474e40139ffSDimitry Andric return __base::__map_.size(); 1475e40139ffSDimitry Andric } 1476e40139ffSDimitry Andric 1477e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 14780b57cec5SDimitry Andric size_type __front_spare() const 14790b57cec5SDimitry Andric { 14800b57cec5SDimitry Andric return __base::__start_; 14810b57cec5SDimitry Andric } 14820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1483e40139ffSDimitry Andric size_type __front_spare_blocks() const { 1484e40139ffSDimitry Andric return __front_spare() / __base::__block_size; 1485e40139ffSDimitry Andric } 1486e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 14870b57cec5SDimitry Andric size_type __back_spare() const 14880b57cec5SDimitry Andric { 14890b57cec5SDimitry Andric return __capacity() - (__base::__start_ + __base::size()); 14900b57cec5SDimitry Andric } 1491e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 1492e40139ffSDimitry Andric size_type __back_spare_blocks() const { 1493e40139ffSDimitry Andric return __back_spare() / __base::__block_size; 1494e40139ffSDimitry Andric } 1495e40139ffSDimitry Andric 1496e40139ffSDimitry Andric private: 1497e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 1498e40139ffSDimitry Andric bool __maybe_remove_front_spare(bool __keep_one = true) { 1499e40139ffSDimitry Andric if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) { 1500e40139ffSDimitry Andric __alloc_traits::deallocate(__base::__alloc(), __base::__map_.front(), 1501e40139ffSDimitry Andric __base::__block_size); 1502e40139ffSDimitry Andric __base::__map_.pop_front(); 1503e40139ffSDimitry Andric __base::__start_ -= __base::__block_size; 1504e40139ffSDimitry Andric return true; 1505e40139ffSDimitry Andric } 1506e40139ffSDimitry Andric return false; 1507e40139ffSDimitry Andric } 1508e40139ffSDimitry Andric 1509e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 1510e40139ffSDimitry Andric bool __maybe_remove_back_spare(bool __keep_one = true) { 1511e40139ffSDimitry Andric if (__back_spare_blocks() >= 2 || (!__keep_one && __back_spare_blocks())) { 1512e40139ffSDimitry Andric __alloc_traits::deallocate(__base::__alloc(), __base::__map_.back(), 1513e40139ffSDimitry Andric __base::__block_size); 1514e40139ffSDimitry Andric __base::__map_.pop_back(); 1515e40139ffSDimitry Andric return true; 1516e40139ffSDimitry Andric } 1517e40139ffSDimitry Andric return false; 1518e40139ffSDimitry Andric } 15190b57cec5SDimitry Andric 15200b57cec5SDimitry Andric template <class _InpIter> 15210b57cec5SDimitry Andric void __append(_InpIter __f, _InpIter __l, 1522480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value && 1523480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InpIter>::value>::type* = 0); 15240b57cec5SDimitry Andric template <class _ForIter> 15250b57cec5SDimitry Andric void __append(_ForIter __f, _ForIter __l, 1526480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type* = 0); 15270b57cec5SDimitry Andric void __append(size_type __n); 15280b57cec5SDimitry Andric void __append(size_type __n, const value_type& __v); 15290b57cec5SDimitry Andric void __erase_to_end(const_iterator __f); 15300b57cec5SDimitry Andric void __add_front_capacity(); 15310b57cec5SDimitry Andric void __add_front_capacity(size_type __n); 15320b57cec5SDimitry Andric void __add_back_capacity(); 15330b57cec5SDimitry Andric void __add_back_capacity(size_type __n); 15340b57cec5SDimitry Andric iterator __move_and_check(iterator __f, iterator __l, iterator __r, 15350b57cec5SDimitry Andric const_pointer& __vt); 15360b57cec5SDimitry Andric iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, 15370b57cec5SDimitry Andric const_pointer& __vt); 15380b57cec5SDimitry Andric void __move_construct_and_check(iterator __f, iterator __l, 15390b57cec5SDimitry Andric iterator __r, const_pointer& __vt); 15400b57cec5SDimitry Andric void __move_construct_backward_and_check(iterator __f, iterator __l, 15410b57cec5SDimitry Andric iterator __r, const_pointer& __vt); 15420b57cec5SDimitry Andric 15430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15440b57cec5SDimitry Andric void __copy_assign_alloc(const deque& __c) 15450b57cec5SDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 15460b57cec5SDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 15470b57cec5SDimitry Andric 15480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15490b57cec5SDimitry Andric void __copy_assign_alloc(const deque& __c, true_type) 15500b57cec5SDimitry Andric { 15510b57cec5SDimitry Andric if (__base::__alloc() != __c.__alloc()) 15520b57cec5SDimitry Andric { 15530b57cec5SDimitry Andric clear(); 15540b57cec5SDimitry Andric shrink_to_fit(); 15550b57cec5SDimitry Andric } 15560b57cec5SDimitry Andric __base::__alloc() = __c.__alloc(); 15570b57cec5SDimitry Andric __base::__map_.__alloc() = __c.__map_.__alloc(); 15580b57cec5SDimitry Andric } 15590b57cec5SDimitry Andric 15600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15610b57cec5SDimitry Andric void __copy_assign_alloc(const deque&, false_type) 15620b57cec5SDimitry Andric {} 15630b57cec5SDimitry Andric 15640b57cec5SDimitry Andric void __move_assign(deque& __c, true_type) 15650b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 15660b57cec5SDimitry Andric void __move_assign(deque& __c, false_type); 15670b57cec5SDimitry Andric}; 15680b57cec5SDimitry Andric 1569*349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 15700b57cec5SDimitry Andrictemplate<class _InputIterator, 1571fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 1572*349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1573*349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 15740b57cec5SDimitry Andric > 15750b57cec5SDimitry Andricdeque(_InputIterator, _InputIterator) 1576fe6060f1SDimitry Andric -> deque<__iter_value_type<_InputIterator>, _Alloc>; 15770b57cec5SDimitry Andric 15780b57cec5SDimitry Andrictemplate<class _InputIterator, 15790b57cec5SDimitry Andric class _Alloc, 1580*349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1581*349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 15820b57cec5SDimitry Andric > 15830b57cec5SDimitry Andricdeque(_InputIterator, _InputIterator, _Alloc) 1584fe6060f1SDimitry Andric -> deque<__iter_value_type<_InputIterator>, _Alloc>; 15850b57cec5SDimitry Andric#endif 15860b57cec5SDimitry Andric 15870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15880b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(size_type __n) 15890b57cec5SDimitry Andric{ 15900b57cec5SDimitry Andric if (__n > 0) 15910b57cec5SDimitry Andric __append(__n); 15920b57cec5SDimitry Andric} 15930b57cec5SDimitry Andric 15940b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 15950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15960b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) 15970b57cec5SDimitry Andric : __base(__a) 15980b57cec5SDimitry Andric{ 15990b57cec5SDimitry Andric if (__n > 0) 16000b57cec5SDimitry Andric __append(__n); 16010b57cec5SDimitry Andric} 16020b57cec5SDimitry Andric#endif 16030b57cec5SDimitry Andric 16040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16050b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) 16060b57cec5SDimitry Andric{ 16070b57cec5SDimitry Andric if (__n > 0) 16080b57cec5SDimitry Andric __append(__n, __v); 16090b57cec5SDimitry Andric} 16100b57cec5SDimitry Andric 16110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16120b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) 16130b57cec5SDimitry Andric : __base(__a) 16140b57cec5SDimitry Andric{ 16150b57cec5SDimitry Andric if (__n > 0) 16160b57cec5SDimitry Andric __append(__n, __v); 16170b57cec5SDimitry Andric} 16180b57cec5SDimitry Andric 16190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16200b57cec5SDimitry Andrictemplate <class _InputIter> 16210b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, 1622480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) 16230b57cec5SDimitry Andric{ 16240b57cec5SDimitry Andric __append(__f, __l); 16250b57cec5SDimitry Andric} 16260b57cec5SDimitry Andric 16270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16280b57cec5SDimitry Andrictemplate <class _InputIter> 16290b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, 1630480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) 16310b57cec5SDimitry Andric : __base(__a) 16320b57cec5SDimitry Andric{ 16330b57cec5SDimitry Andric __append(__f, __l); 16340b57cec5SDimitry Andric} 16350b57cec5SDimitry Andric 16360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16370b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(const deque& __c) 16380b57cec5SDimitry Andric : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) 16390b57cec5SDimitry Andric{ 16400b57cec5SDimitry Andric __append(__c.begin(), __c.end()); 16410b57cec5SDimitry Andric} 16420b57cec5SDimitry Andric 16430b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1644fe6060f1SDimitry Andricdeque<_Tp, _Allocator>::deque(const deque& __c, const __identity_t<allocator_type>& __a) 16450b57cec5SDimitry Andric : __base(__a) 16460b57cec5SDimitry Andric{ 16470b57cec5SDimitry Andric __append(__c.begin(), __c.end()); 16480b57cec5SDimitry Andric} 16490b57cec5SDimitry Andric 16500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16510b57cec5SDimitry Andricdeque<_Tp, _Allocator>& 16520b57cec5SDimitry Andricdeque<_Tp, _Allocator>::operator=(const deque& __c) 16530b57cec5SDimitry Andric{ 1654*349cc55cSDimitry Andric if (this != _VSTD::addressof(__c)) 16550b57cec5SDimitry Andric { 16560b57cec5SDimitry Andric __copy_assign_alloc(__c); 16570b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 16580b57cec5SDimitry Andric } 16590b57cec5SDimitry Andric return *this; 16600b57cec5SDimitry Andric} 16610b57cec5SDimitry Andric 16620b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16630b57cec5SDimitry Andric 16640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16650b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) 16660b57cec5SDimitry Andric{ 16670b57cec5SDimitry Andric __append(__il.begin(), __il.end()); 16680b57cec5SDimitry Andric} 16690b57cec5SDimitry Andric 16700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16710b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) 16720b57cec5SDimitry Andric : __base(__a) 16730b57cec5SDimitry Andric{ 16740b57cec5SDimitry Andric __append(__il.begin(), __il.end()); 16750b57cec5SDimitry Andric} 16760b57cec5SDimitry Andric 16770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16780b57cec5SDimitry Andricinline 16790b57cec5SDimitry Andricdeque<_Tp, _Allocator>::deque(deque&& __c) 16800b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 16810b57cec5SDimitry Andric : __base(_VSTD::move(__c)) 16820b57cec5SDimitry Andric{ 16830b57cec5SDimitry Andric} 16840b57cec5SDimitry Andric 16850b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16860b57cec5SDimitry Andricinline 1687fe6060f1SDimitry Andricdeque<_Tp, _Allocator>::deque(deque&& __c, const __identity_t<allocator_type>& __a) 16880b57cec5SDimitry Andric : __base(_VSTD::move(__c), __a) 16890b57cec5SDimitry Andric{ 16900b57cec5SDimitry Andric if (__a != __c.__alloc()) 16910b57cec5SDimitry Andric { 16920b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 16930b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 16940b57cec5SDimitry Andric } 16950b57cec5SDimitry Andric} 16960b57cec5SDimitry Andric 16970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16980b57cec5SDimitry Andricinline 16990b57cec5SDimitry Andricdeque<_Tp, _Allocator>& 17000b57cec5SDimitry Andricdeque<_Tp, _Allocator>::operator=(deque&& __c) 17010b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 17020b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 17030b57cec5SDimitry Andric{ 17040b57cec5SDimitry Andric __move_assign(__c, integral_constant<bool, 17050b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 17060b57cec5SDimitry Andric return *this; 17070b57cec5SDimitry Andric} 17080b57cec5SDimitry Andric 17090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17100b57cec5SDimitry Andricvoid 17110b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) 17120b57cec5SDimitry Andric{ 17130b57cec5SDimitry Andric if (__base::__alloc() != __c.__alloc()) 17140b57cec5SDimitry Andric { 17150b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 17160b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 17170b57cec5SDimitry Andric } 17180b57cec5SDimitry Andric else 17190b57cec5SDimitry Andric __move_assign(__c, true_type()); 17200b57cec5SDimitry Andric} 17210b57cec5SDimitry Andric 17220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17230b57cec5SDimitry Andricvoid 17240b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) 17250b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 17260b57cec5SDimitry Andric{ 17270b57cec5SDimitry Andric clear(); 17280b57cec5SDimitry Andric shrink_to_fit(); 17290b57cec5SDimitry Andric __base::__move_assign(__c); 17300b57cec5SDimitry Andric} 17310b57cec5SDimitry Andric 17320b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 17330b57cec5SDimitry Andric 17340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17350b57cec5SDimitry Andrictemplate <class _InputIter> 17360b57cec5SDimitry Andricvoid 17370b57cec5SDimitry Andricdeque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, 1738480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && 1739480093f4SDimitry Andric !__is_cpp17_random_access_iterator<_InputIter>::value>::type*) 17400b57cec5SDimitry Andric{ 17410b57cec5SDimitry Andric iterator __i = __base::begin(); 17420b57cec5SDimitry Andric iterator __e = __base::end(); 17430b57cec5SDimitry Andric for (; __f != __l && __i != __e; ++__f, (void) ++__i) 17440b57cec5SDimitry Andric *__i = *__f; 17450b57cec5SDimitry Andric if (__f != __l) 17460b57cec5SDimitry Andric __append(__f, __l); 17470b57cec5SDimitry Andric else 17480b57cec5SDimitry Andric __erase_to_end(__i); 17490b57cec5SDimitry Andric} 17500b57cec5SDimitry Andric 17510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17520b57cec5SDimitry Andrictemplate <class _RAIter> 17530b57cec5SDimitry Andricvoid 17540b57cec5SDimitry Andricdeque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, 1755480093f4SDimitry Andric typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) 17560b57cec5SDimitry Andric{ 17570b57cec5SDimitry Andric if (static_cast<size_type>(__l - __f) > __base::size()) 17580b57cec5SDimitry Andric { 17590b57cec5SDimitry Andric _RAIter __m = __f + __base::size(); 17600b57cec5SDimitry Andric _VSTD::copy(__f, __m, __base::begin()); 17610b57cec5SDimitry Andric __append(__m, __l); 17620b57cec5SDimitry Andric } 17630b57cec5SDimitry Andric else 17640b57cec5SDimitry Andric __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); 17650b57cec5SDimitry Andric} 17660b57cec5SDimitry Andric 17670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17680b57cec5SDimitry Andricvoid 17690b57cec5SDimitry Andricdeque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) 17700b57cec5SDimitry Andric{ 17710b57cec5SDimitry Andric if (__n > __base::size()) 17720b57cec5SDimitry Andric { 17730b57cec5SDimitry Andric _VSTD::fill_n(__base::begin(), __base::size(), __v); 17740b57cec5SDimitry Andric __n -= __base::size(); 17750b57cec5SDimitry Andric __append(__n, __v); 17760b57cec5SDimitry Andric } 17770b57cec5SDimitry Andric else 17780b57cec5SDimitry Andric __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); 17790b57cec5SDimitry Andric} 17800b57cec5SDimitry Andric 17810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17820b57cec5SDimitry Andricinline 17830b57cec5SDimitry Andric_Allocator 17840b57cec5SDimitry Andricdeque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT 17850b57cec5SDimitry Andric{ 17860b57cec5SDimitry Andric return __base::__alloc(); 17870b57cec5SDimitry Andric} 17880b57cec5SDimitry Andric 17890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17900b57cec5SDimitry Andricvoid 17910b57cec5SDimitry Andricdeque<_Tp, _Allocator>::resize(size_type __n) 17920b57cec5SDimitry Andric{ 17930b57cec5SDimitry Andric if (__n > __base::size()) 17940b57cec5SDimitry Andric __append(__n - __base::size()); 17950b57cec5SDimitry Andric else if (__n < __base::size()) 17960b57cec5SDimitry Andric __erase_to_end(__base::begin() + __n); 17970b57cec5SDimitry Andric} 17980b57cec5SDimitry Andric 17990b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18000b57cec5SDimitry Andricvoid 18010b57cec5SDimitry Andricdeque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) 18020b57cec5SDimitry Andric{ 18030b57cec5SDimitry Andric if (__n > __base::size()) 18040b57cec5SDimitry Andric __append(__n - __base::size(), __v); 18050b57cec5SDimitry Andric else if (__n < __base::size()) 18060b57cec5SDimitry Andric __erase_to_end(__base::begin() + __n); 18070b57cec5SDimitry Andric} 18080b57cec5SDimitry Andric 18090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18100b57cec5SDimitry Andricvoid 18110b57cec5SDimitry Andricdeque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 18120b57cec5SDimitry Andric{ 18130b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 18140b57cec5SDimitry Andric if (empty()) 18150b57cec5SDimitry Andric { 18160b57cec5SDimitry Andric while (__base::__map_.size() > 0) 18170b57cec5SDimitry Andric { 18180b57cec5SDimitry Andric __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 18190b57cec5SDimitry Andric __base::__map_.pop_back(); 18200b57cec5SDimitry Andric } 18210b57cec5SDimitry Andric __base::__start_ = 0; 18220b57cec5SDimitry Andric } 18230b57cec5SDimitry Andric else 18240b57cec5SDimitry Andric { 1825e40139ffSDimitry Andric __maybe_remove_front_spare(/*__keep_one=*/false); 1826e40139ffSDimitry Andric __maybe_remove_back_spare(/*__keep_one=*/false); 18270b57cec5SDimitry Andric } 18280b57cec5SDimitry Andric __base::__map_.shrink_to_fit(); 18290b57cec5SDimitry Andric} 18300b57cec5SDimitry Andric 18310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18320b57cec5SDimitry Andricinline 18330b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 18340b57cec5SDimitry Andricdeque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT 18350b57cec5SDimitry Andric{ 18360b57cec5SDimitry Andric size_type __p = __base::__start_ + __i; 18370b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 18380b57cec5SDimitry Andric} 18390b57cec5SDimitry Andric 18400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18410b57cec5SDimitry Andricinline 18420b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::const_reference 18430b57cec5SDimitry Andricdeque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT 18440b57cec5SDimitry Andric{ 18450b57cec5SDimitry Andric size_type __p = __base::__start_ + __i; 18460b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 18470b57cec5SDimitry Andric} 18480b57cec5SDimitry Andric 18490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18500b57cec5SDimitry Andricinline 18510b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 18520b57cec5SDimitry Andricdeque<_Tp, _Allocator>::at(size_type __i) 18530b57cec5SDimitry Andric{ 18540b57cec5SDimitry Andric if (__i >= __base::size()) 1855*349cc55cSDimitry Andric _VSTD::__throw_out_of_range("deque"); 18560b57cec5SDimitry Andric size_type __p = __base::__start_ + __i; 18570b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 18580b57cec5SDimitry Andric} 18590b57cec5SDimitry Andric 18600b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18610b57cec5SDimitry Andricinline 18620b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::const_reference 18630b57cec5SDimitry Andricdeque<_Tp, _Allocator>::at(size_type __i) const 18640b57cec5SDimitry Andric{ 18650b57cec5SDimitry Andric if (__i >= __base::size()) 1866*349cc55cSDimitry Andric _VSTD::__throw_out_of_range("deque"); 18670b57cec5SDimitry Andric size_type __p = __base::__start_ + __i; 18680b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 18690b57cec5SDimitry Andric} 18700b57cec5SDimitry Andric 18710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18720b57cec5SDimitry Andricinline 18730b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 18740b57cec5SDimitry Andricdeque<_Tp, _Allocator>::front() _NOEXCEPT 18750b57cec5SDimitry Andric{ 18760b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) 18770b57cec5SDimitry Andric + __base::__start_ % __base::__block_size); 18780b57cec5SDimitry Andric} 18790b57cec5SDimitry Andric 18800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18810b57cec5SDimitry Andricinline 18820b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::const_reference 18830b57cec5SDimitry Andricdeque<_Tp, _Allocator>::front() const _NOEXCEPT 18840b57cec5SDimitry Andric{ 18850b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) 18860b57cec5SDimitry Andric + __base::__start_ % __base::__block_size); 18870b57cec5SDimitry Andric} 18880b57cec5SDimitry Andric 18890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18900b57cec5SDimitry Andricinline 18910b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 18920b57cec5SDimitry Andricdeque<_Tp, _Allocator>::back() _NOEXCEPT 18930b57cec5SDimitry Andric{ 18940b57cec5SDimitry Andric size_type __p = __base::size() + __base::__start_ - 1; 18950b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 18960b57cec5SDimitry Andric} 18970b57cec5SDimitry Andric 18980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18990b57cec5SDimitry Andricinline 19000b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::const_reference 19010b57cec5SDimitry Andricdeque<_Tp, _Allocator>::back() const _NOEXCEPT 19020b57cec5SDimitry Andric{ 19030b57cec5SDimitry Andric size_type __p = __base::size() + __base::__start_ - 1; 19040b57cec5SDimitry Andric return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 19050b57cec5SDimitry Andric} 19060b57cec5SDimitry Andric 19070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19080b57cec5SDimitry Andricvoid 19090b57cec5SDimitry Andricdeque<_Tp, _Allocator>::push_back(const value_type& __v) 19100b57cec5SDimitry Andric{ 19110b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19120b57cec5SDimitry Andric if (__back_spare() == 0) 19130b57cec5SDimitry Andric __add_back_capacity(); 19140b57cec5SDimitry Andric // __back_spare() >= 1 19150b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); 19160b57cec5SDimitry Andric ++__base::size(); 19170b57cec5SDimitry Andric} 19180b57cec5SDimitry Andric 19190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19200b57cec5SDimitry Andricvoid 19210b57cec5SDimitry Andricdeque<_Tp, _Allocator>::push_front(const value_type& __v) 19220b57cec5SDimitry Andric{ 19230b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19240b57cec5SDimitry Andric if (__front_spare() == 0) 19250b57cec5SDimitry Andric __add_front_capacity(); 19260b57cec5SDimitry Andric // __front_spare() >= 1 19270b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); 19280b57cec5SDimitry Andric --__base::__start_; 19290b57cec5SDimitry Andric ++__base::size(); 19300b57cec5SDimitry Andric} 19310b57cec5SDimitry Andric 19320b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 19330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19340b57cec5SDimitry Andricvoid 19350b57cec5SDimitry Andricdeque<_Tp, _Allocator>::push_back(value_type&& __v) 19360b57cec5SDimitry Andric{ 19370b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19380b57cec5SDimitry Andric if (__back_spare() == 0) 19390b57cec5SDimitry Andric __add_back_capacity(); 19400b57cec5SDimitry Andric // __back_spare() >= 1 19410b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); 19420b57cec5SDimitry Andric ++__base::size(); 19430b57cec5SDimitry Andric} 19440b57cec5SDimitry Andric 19450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19460b57cec5SDimitry Andrictemplate <class... _Args> 19470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 19480b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 19490b57cec5SDimitry Andric#else 19500b57cec5SDimitry Andricvoid 19510b57cec5SDimitry Andric#endif 19520b57cec5SDimitry Andricdeque<_Tp, _Allocator>::emplace_back(_Args&&... __args) 19530b57cec5SDimitry Andric{ 19540b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19550b57cec5SDimitry Andric if (__back_spare() == 0) 19560b57cec5SDimitry Andric __add_back_capacity(); 19570b57cec5SDimitry Andric // __back_spare() >= 1 19580b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), 19590b57cec5SDimitry Andric _VSTD::forward<_Args>(__args)...); 19600b57cec5SDimitry Andric ++__base::size(); 19610b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 19620b57cec5SDimitry Andric return *--__base::end(); 19630b57cec5SDimitry Andric#endif 19640b57cec5SDimitry Andric} 19650b57cec5SDimitry Andric 19660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19670b57cec5SDimitry Andricvoid 19680b57cec5SDimitry Andricdeque<_Tp, _Allocator>::push_front(value_type&& __v) 19690b57cec5SDimitry Andric{ 19700b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19710b57cec5SDimitry Andric if (__front_spare() == 0) 19720b57cec5SDimitry Andric __add_front_capacity(); 19730b57cec5SDimitry Andric // __front_spare() >= 1 19740b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); 19750b57cec5SDimitry Andric --__base::__start_; 19760b57cec5SDimitry Andric ++__base::size(); 19770b57cec5SDimitry Andric} 19780b57cec5SDimitry Andric 19790b57cec5SDimitry Andric 19800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19810b57cec5SDimitry Andrictemplate <class... _Args> 19820b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 19830b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::reference 19840b57cec5SDimitry Andric#else 19850b57cec5SDimitry Andricvoid 19860b57cec5SDimitry Andric#endif 19870b57cec5SDimitry Andricdeque<_Tp, _Allocator>::emplace_front(_Args&&... __args) 19880b57cec5SDimitry Andric{ 19890b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 19900b57cec5SDimitry Andric if (__front_spare() == 0) 19910b57cec5SDimitry Andric __add_front_capacity(); 19920b57cec5SDimitry Andric // __front_spare() >= 1 19930b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); 19940b57cec5SDimitry Andric --__base::__start_; 19950b57cec5SDimitry Andric ++__base::size(); 19960b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 19970b57cec5SDimitry Andric return *__base::begin(); 19980b57cec5SDimitry Andric#endif 19990b57cec5SDimitry Andric} 20000b57cec5SDimitry Andric 20010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20020b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 20030b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) 20040b57cec5SDimitry Andric{ 20050b57cec5SDimitry Andric size_type __pos = __p - __base::begin(); 20060b57cec5SDimitry Andric size_type __to_end = __base::size() - __pos; 20070b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 20080b57cec5SDimitry Andric if (__pos < __to_end) 20090b57cec5SDimitry Andric { // insert by shifting things backward 20100b57cec5SDimitry Andric if (__front_spare() == 0) 20110b57cec5SDimitry Andric __add_front_capacity(); 20120b57cec5SDimitry Andric // __front_spare() >= 1 20130b57cec5SDimitry Andric if (__pos == 0) 20140b57cec5SDimitry Andric { 20150b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); 20160b57cec5SDimitry Andric --__base::__start_; 20170b57cec5SDimitry Andric ++__base::size(); 20180b57cec5SDimitry Andric } 20190b57cec5SDimitry Andric else 20200b57cec5SDimitry Andric { 20210b57cec5SDimitry Andric iterator __b = __base::begin(); 20220b57cec5SDimitry Andric iterator __bm1 = _VSTD::prev(__b); 20230b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 20240b57cec5SDimitry Andric --__base::__start_; 20250b57cec5SDimitry Andric ++__base::size(); 20260b57cec5SDimitry Andric if (__pos > 1) 20270b57cec5SDimitry Andric __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); 20280b57cec5SDimitry Andric *__b = _VSTD::move(__v); 20290b57cec5SDimitry Andric } 20300b57cec5SDimitry Andric } 20310b57cec5SDimitry Andric else 20320b57cec5SDimitry Andric { // insert by shifting things forward 20330b57cec5SDimitry Andric if (__back_spare() == 0) 20340b57cec5SDimitry Andric __add_back_capacity(); 20350b57cec5SDimitry Andric // __back_capacity >= 1 20360b57cec5SDimitry Andric size_type __de = __base::size() - __pos; 20370b57cec5SDimitry Andric if (__de == 0) 20380b57cec5SDimitry Andric { 20390b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); 20400b57cec5SDimitry Andric ++__base::size(); 20410b57cec5SDimitry Andric } 20420b57cec5SDimitry Andric else 20430b57cec5SDimitry Andric { 20440b57cec5SDimitry Andric iterator __e = __base::end(); 20450b57cec5SDimitry Andric iterator __em1 = _VSTD::prev(__e); 20460b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 20470b57cec5SDimitry Andric ++__base::size(); 20480b57cec5SDimitry Andric if (__de > 1) 20490b57cec5SDimitry Andric __e = _VSTD::move_backward(__e - __de, __em1, __e); 20500b57cec5SDimitry Andric *--__e = _VSTD::move(__v); 20510b57cec5SDimitry Andric } 20520b57cec5SDimitry Andric } 20530b57cec5SDimitry Andric return __base::begin() + __pos; 20540b57cec5SDimitry Andric} 20550b57cec5SDimitry Andric 20560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20570b57cec5SDimitry Andrictemplate <class... _Args> 20580b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 20590b57cec5SDimitry Andricdeque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) 20600b57cec5SDimitry Andric{ 20610b57cec5SDimitry Andric size_type __pos = __p - __base::begin(); 20620b57cec5SDimitry Andric size_type __to_end = __base::size() - __pos; 20630b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 20640b57cec5SDimitry Andric if (__pos < __to_end) 20650b57cec5SDimitry Andric { // insert by shifting things backward 20660b57cec5SDimitry Andric if (__front_spare() == 0) 20670b57cec5SDimitry Andric __add_front_capacity(); 20680b57cec5SDimitry Andric // __front_spare() >= 1 20690b57cec5SDimitry Andric if (__pos == 0) 20700b57cec5SDimitry Andric { 20710b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); 20720b57cec5SDimitry Andric --__base::__start_; 20730b57cec5SDimitry Andric ++__base::size(); 20740b57cec5SDimitry Andric } 20750b57cec5SDimitry Andric else 20760b57cec5SDimitry Andric { 20770b57cec5SDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 20780b57cec5SDimitry Andric iterator __b = __base::begin(); 20790b57cec5SDimitry Andric iterator __bm1 = _VSTD::prev(__b); 20800b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 20810b57cec5SDimitry Andric --__base::__start_; 20820b57cec5SDimitry Andric ++__base::size(); 20830b57cec5SDimitry Andric if (__pos > 1) 20840b57cec5SDimitry Andric __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); 20850b57cec5SDimitry Andric *__b = _VSTD::move(__tmp.get()); 20860b57cec5SDimitry Andric } 20870b57cec5SDimitry Andric } 20880b57cec5SDimitry Andric else 20890b57cec5SDimitry Andric { // insert by shifting things forward 20900b57cec5SDimitry Andric if (__back_spare() == 0) 20910b57cec5SDimitry Andric __add_back_capacity(); 20920b57cec5SDimitry Andric // __back_capacity >= 1 20930b57cec5SDimitry Andric size_type __de = __base::size() - __pos; 20940b57cec5SDimitry Andric if (__de == 0) 20950b57cec5SDimitry Andric { 20960b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); 20970b57cec5SDimitry Andric ++__base::size(); 20980b57cec5SDimitry Andric } 20990b57cec5SDimitry Andric else 21000b57cec5SDimitry Andric { 21010b57cec5SDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 21020b57cec5SDimitry Andric iterator __e = __base::end(); 21030b57cec5SDimitry Andric iterator __em1 = _VSTD::prev(__e); 21040b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 21050b57cec5SDimitry Andric ++__base::size(); 21060b57cec5SDimitry Andric if (__de > 1) 21070b57cec5SDimitry Andric __e = _VSTD::move_backward(__e - __de, __em1, __e); 21080b57cec5SDimitry Andric *--__e = _VSTD::move(__tmp.get()); 21090b57cec5SDimitry Andric } 21100b57cec5SDimitry Andric } 21110b57cec5SDimitry Andric return __base::begin() + __pos; 21120b57cec5SDimitry Andric} 21130b57cec5SDimitry Andric 21140b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 21150b57cec5SDimitry Andric 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21180b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 21190b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) 21200b57cec5SDimitry Andric{ 21210b57cec5SDimitry Andric size_type __pos = __p - __base::begin(); 21220b57cec5SDimitry Andric size_type __to_end = __base::size() - __pos; 21230b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 21240b57cec5SDimitry Andric if (__pos < __to_end) 21250b57cec5SDimitry Andric { // insert by shifting things backward 21260b57cec5SDimitry Andric if (__front_spare() == 0) 21270b57cec5SDimitry Andric __add_front_capacity(); 21280b57cec5SDimitry Andric // __front_spare() >= 1 21290b57cec5SDimitry Andric if (__pos == 0) 21300b57cec5SDimitry Andric { 21310b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); 21320b57cec5SDimitry Andric --__base::__start_; 21330b57cec5SDimitry Andric ++__base::size(); 21340b57cec5SDimitry Andric } 21350b57cec5SDimitry Andric else 21360b57cec5SDimitry Andric { 21370b57cec5SDimitry Andric const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 21380b57cec5SDimitry Andric iterator __b = __base::begin(); 21390b57cec5SDimitry Andric iterator __bm1 = _VSTD::prev(__b); 21400b57cec5SDimitry Andric if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) 21410b57cec5SDimitry Andric __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); 21420b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 21430b57cec5SDimitry Andric --__base::__start_; 21440b57cec5SDimitry Andric ++__base::size(); 21450b57cec5SDimitry Andric if (__pos > 1) 21460b57cec5SDimitry Andric __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); 21470b57cec5SDimitry Andric *__b = *__vt; 21480b57cec5SDimitry Andric } 21490b57cec5SDimitry Andric } 21500b57cec5SDimitry Andric else 21510b57cec5SDimitry Andric { // insert by shifting things forward 21520b57cec5SDimitry Andric if (__back_spare() == 0) 21530b57cec5SDimitry Andric __add_back_capacity(); 21540b57cec5SDimitry Andric // __back_capacity >= 1 21550b57cec5SDimitry Andric size_type __de = __base::size() - __pos; 21560b57cec5SDimitry Andric if (__de == 0) 21570b57cec5SDimitry Andric { 21580b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); 21590b57cec5SDimitry Andric ++__base::size(); 21600b57cec5SDimitry Andric } 21610b57cec5SDimitry Andric else 21620b57cec5SDimitry Andric { 21630b57cec5SDimitry Andric const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 21640b57cec5SDimitry Andric iterator __e = __base::end(); 21650b57cec5SDimitry Andric iterator __em1 = _VSTD::prev(__e); 21660b57cec5SDimitry Andric if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) 21670b57cec5SDimitry Andric __vt = pointer_traits<const_pointer>::pointer_to(*__e); 21680b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 21690b57cec5SDimitry Andric ++__base::size(); 21700b57cec5SDimitry Andric if (__de > 1) 21710b57cec5SDimitry Andric __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); 21720b57cec5SDimitry Andric *--__e = *__vt; 21730b57cec5SDimitry Andric } 21740b57cec5SDimitry Andric } 21750b57cec5SDimitry Andric return __base::begin() + __pos; 21760b57cec5SDimitry Andric} 21770b57cec5SDimitry Andric 21780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21790b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 21800b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) 21810b57cec5SDimitry Andric{ 21820b57cec5SDimitry Andric size_type __pos = __p - __base::begin(); 21830b57cec5SDimitry Andric size_type __to_end = __base::size() - __pos; 21840b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 21850b57cec5SDimitry Andric if (__pos < __to_end) 21860b57cec5SDimitry Andric { // insert by shifting things backward 21870b57cec5SDimitry Andric if (__n > __front_spare()) 21880b57cec5SDimitry Andric __add_front_capacity(__n - __front_spare()); 21890b57cec5SDimitry Andric // __n <= __front_spare() 21900b57cec5SDimitry Andric iterator __old_begin = __base::begin(); 21910b57cec5SDimitry Andric iterator __i = __old_begin; 21920b57cec5SDimitry Andric if (__n > __pos) 21930b57cec5SDimitry Andric { 21940b57cec5SDimitry Andric for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) 21950b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); 21960b57cec5SDimitry Andric __n = __pos; 21970b57cec5SDimitry Andric } 21980b57cec5SDimitry Andric if (__n > 0) 21990b57cec5SDimitry Andric { 22000b57cec5SDimitry Andric const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 22010b57cec5SDimitry Andric iterator __obn = __old_begin + __n; 22020b57cec5SDimitry Andric __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); 22030b57cec5SDimitry Andric if (__n < __pos) 22040b57cec5SDimitry Andric __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); 22050b57cec5SDimitry Andric _VSTD::fill_n(__old_begin, __n, *__vt); 22060b57cec5SDimitry Andric } 22070b57cec5SDimitry Andric } 22080b57cec5SDimitry Andric else 22090b57cec5SDimitry Andric { // insert by shifting things forward 22100b57cec5SDimitry Andric size_type __back_capacity = __back_spare(); 22110b57cec5SDimitry Andric if (__n > __back_capacity) 22120b57cec5SDimitry Andric __add_back_capacity(__n - __back_capacity); 22130b57cec5SDimitry Andric // __n <= __back_capacity 22140b57cec5SDimitry Andric iterator __old_end = __base::end(); 22150b57cec5SDimitry Andric iterator __i = __old_end; 22160b57cec5SDimitry Andric size_type __de = __base::size() - __pos; 22170b57cec5SDimitry Andric if (__n > __de) 22180b57cec5SDimitry Andric { 2219*349cc55cSDimitry Andric for (size_type __m = __n - __de; __m; --__m, (void) ++__i, ++__base::size()) 22200b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); 22210b57cec5SDimitry Andric __n = __de; 22220b57cec5SDimitry Andric } 22230b57cec5SDimitry Andric if (__n > 0) 22240b57cec5SDimitry Andric { 22250b57cec5SDimitry Andric const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 22260b57cec5SDimitry Andric iterator __oen = __old_end - __n; 22270b57cec5SDimitry Andric __move_construct_and_check(__oen, __old_end, __i, __vt); 22280b57cec5SDimitry Andric if (__n < __de) 22290b57cec5SDimitry Andric __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); 22300b57cec5SDimitry Andric _VSTD::fill_n(__old_end - __n, __n, *__vt); 22310b57cec5SDimitry Andric } 22320b57cec5SDimitry Andric } 22330b57cec5SDimitry Andric return __base::begin() + __pos; 22340b57cec5SDimitry Andric} 22350b57cec5SDimitry Andric 22360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 22370b57cec5SDimitry Andrictemplate <class _InputIter> 22380b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 22390b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, 2240480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InputIter>::value 2241480093f4SDimitry Andric &&!__is_cpp17_forward_iterator<_InputIter>::value>::type*) 22420b57cec5SDimitry Andric{ 22430b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); 22440b57cec5SDimitry Andric __buf.__construct_at_end(__f, __l); 22450b57cec5SDimitry Andric typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; 22460b57cec5SDimitry Andric return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); 22470b57cec5SDimitry Andric} 22480b57cec5SDimitry Andric 22490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 22500b57cec5SDimitry Andrictemplate <class _ForwardIterator> 22510b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 22520b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, 2253480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value 2254480093f4SDimitry Andric &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type*) 22550b57cec5SDimitry Andric{ 22560b57cec5SDimitry Andric size_type __n = _VSTD::distance(__f, __l); 22570b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); 22580b57cec5SDimitry Andric __buf.__construct_at_end(__f, __l); 22590b57cec5SDimitry Andric typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; 22600b57cec5SDimitry Andric return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); 22610b57cec5SDimitry Andric} 22620b57cec5SDimitry Andric 22630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 22640b57cec5SDimitry Andrictemplate <class _BiIter> 22650b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 22660b57cec5SDimitry Andricdeque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, 2267480093f4SDimitry Andric typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type*) 22680b57cec5SDimitry Andric{ 22690b57cec5SDimitry Andric size_type __n = _VSTD::distance(__f, __l); 22700b57cec5SDimitry Andric size_type __pos = __p - __base::begin(); 22710b57cec5SDimitry Andric size_type __to_end = __base::size() - __pos; 22720b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 22730b57cec5SDimitry Andric if (__pos < __to_end) 22740b57cec5SDimitry Andric { // insert by shifting things backward 22750b57cec5SDimitry Andric if (__n > __front_spare()) 22760b57cec5SDimitry Andric __add_front_capacity(__n - __front_spare()); 22770b57cec5SDimitry Andric // __n <= __front_spare() 22780b57cec5SDimitry Andric iterator __old_begin = __base::begin(); 22790b57cec5SDimitry Andric iterator __i = __old_begin; 22800b57cec5SDimitry Andric _BiIter __m = __f; 22810b57cec5SDimitry Andric if (__n > __pos) 22820b57cec5SDimitry Andric { 22830b57cec5SDimitry Andric __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); 22840b57cec5SDimitry Andric for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) 22850b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); 22860b57cec5SDimitry Andric __n = __pos; 22870b57cec5SDimitry Andric } 22880b57cec5SDimitry Andric if (__n > 0) 22890b57cec5SDimitry Andric { 22900b57cec5SDimitry Andric iterator __obn = __old_begin + __n; 22910b57cec5SDimitry Andric for (iterator __j = __obn; __j != __old_begin;) 22920b57cec5SDimitry Andric { 22930b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); 22940b57cec5SDimitry Andric --__base::__start_; 22950b57cec5SDimitry Andric ++__base::size(); 22960b57cec5SDimitry Andric } 22970b57cec5SDimitry Andric if (__n < __pos) 22980b57cec5SDimitry Andric __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); 22990b57cec5SDimitry Andric _VSTD::copy(__m, __l, __old_begin); 23000b57cec5SDimitry Andric } 23010b57cec5SDimitry Andric } 23020b57cec5SDimitry Andric else 23030b57cec5SDimitry Andric { // insert by shifting things forward 23040b57cec5SDimitry Andric size_type __back_capacity = __back_spare(); 23050b57cec5SDimitry Andric if (__n > __back_capacity) 23060b57cec5SDimitry Andric __add_back_capacity(__n - __back_capacity); 23070b57cec5SDimitry Andric // __n <= __back_capacity 23080b57cec5SDimitry Andric iterator __old_end = __base::end(); 23090b57cec5SDimitry Andric iterator __i = __old_end; 23100b57cec5SDimitry Andric _BiIter __m = __l; 23110b57cec5SDimitry Andric size_type __de = __base::size() - __pos; 23120b57cec5SDimitry Andric if (__n > __de) 23130b57cec5SDimitry Andric { 23140b57cec5SDimitry Andric __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); 23150b57cec5SDimitry Andric for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) 23160b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); 23170b57cec5SDimitry Andric __n = __de; 23180b57cec5SDimitry Andric } 23190b57cec5SDimitry Andric if (__n > 0) 23200b57cec5SDimitry Andric { 23210b57cec5SDimitry Andric iterator __oen = __old_end - __n; 2322*349cc55cSDimitry Andric for (iterator __j = __oen; __j != __old_end; ++__i, (void) ++__j, ++__base::size()) 23230b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); 23240b57cec5SDimitry Andric if (__n < __de) 23250b57cec5SDimitry Andric __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); 23260b57cec5SDimitry Andric _VSTD::copy_backward(__f, __m, __old_end); 23270b57cec5SDimitry Andric } 23280b57cec5SDimitry Andric } 23290b57cec5SDimitry Andric return __base::begin() + __pos; 23300b57cec5SDimitry Andric} 23310b57cec5SDimitry Andric 23320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 23330b57cec5SDimitry Andrictemplate <class _InpIter> 23340b57cec5SDimitry Andricvoid 23350b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, 2336480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value && 2337480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InpIter>::value>::type*) 23380b57cec5SDimitry Andric{ 23390b57cec5SDimitry Andric for (; __f != __l; ++__f) 23400b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 23410b57cec5SDimitry Andric push_back(*__f); 23420b57cec5SDimitry Andric#else 23430b57cec5SDimitry Andric emplace_back(*__f); 23440b57cec5SDimitry Andric#endif 23450b57cec5SDimitry Andric} 23460b57cec5SDimitry Andric 23470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 23480b57cec5SDimitry Andrictemplate <class _ForIter> 23490b57cec5SDimitry Andricvoid 23500b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, 2351480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type*) 23520b57cec5SDimitry Andric{ 23530b57cec5SDimitry Andric size_type __n = _VSTD::distance(__f, __l); 23540b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 23550b57cec5SDimitry Andric size_type __back_capacity = __back_spare(); 23560b57cec5SDimitry Andric if (__n > __back_capacity) 23570b57cec5SDimitry Andric __add_back_capacity(__n - __back_capacity); 23580b57cec5SDimitry Andric // __n <= __back_capacity 2359e40139ffSDimitry Andric for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { 2360e40139ffSDimitry Andric _ConstructTransaction __tx(this, __br); 2361e40139ffSDimitry Andric for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__f) { 2362e8d8bef9SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), *__f); 2363e40139ffSDimitry Andric } 2364e40139ffSDimitry Andric } 23650b57cec5SDimitry Andric} 23660b57cec5SDimitry Andric 23670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 23680b57cec5SDimitry Andricvoid 23690b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__append(size_type __n) 23700b57cec5SDimitry Andric{ 23710b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 23720b57cec5SDimitry Andric size_type __back_capacity = __back_spare(); 23730b57cec5SDimitry Andric if (__n > __back_capacity) 23740b57cec5SDimitry Andric __add_back_capacity(__n - __back_capacity); 23750b57cec5SDimitry Andric // __n <= __back_capacity 2376e40139ffSDimitry Andric for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { 2377e40139ffSDimitry Andric _ConstructTransaction __tx(this, __br); 2378e40139ffSDimitry Andric for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { 2379e8d8bef9SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_)); 2380e40139ffSDimitry Andric } 2381e40139ffSDimitry Andric } 23820b57cec5SDimitry Andric} 23830b57cec5SDimitry Andric 23840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 23850b57cec5SDimitry Andricvoid 23860b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) 23870b57cec5SDimitry Andric{ 23880b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 23890b57cec5SDimitry Andric size_type __back_capacity = __back_spare(); 23900b57cec5SDimitry Andric if (__n > __back_capacity) 23910b57cec5SDimitry Andric __add_back_capacity(__n - __back_capacity); 23920b57cec5SDimitry Andric // __n <= __back_capacity 2393e40139ffSDimitry Andric for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { 2394e40139ffSDimitry Andric _ConstructTransaction __tx(this, __br); 2395e40139ffSDimitry Andric for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { 2396e8d8bef9SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), __v); 2397e40139ffSDimitry Andric } 2398e40139ffSDimitry Andric } 2399e40139ffSDimitry Andric 24000b57cec5SDimitry Andric} 24010b57cec5SDimitry Andric 24020b57cec5SDimitry Andric// Create front capacity for one block of elements. 24030b57cec5SDimitry Andric// Strong guarantee. Either do it or don't touch anything. 24040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 24050b57cec5SDimitry Andricvoid 24060b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__add_front_capacity() 24070b57cec5SDimitry Andric{ 24080b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 24090b57cec5SDimitry Andric if (__back_spare() >= __base::__block_size) 24100b57cec5SDimitry Andric { 24110b57cec5SDimitry Andric __base::__start_ += __base::__block_size; 24120b57cec5SDimitry Andric pointer __pt = __base::__map_.back(); 24130b57cec5SDimitry Andric __base::__map_.pop_back(); 24140b57cec5SDimitry Andric __base::__map_.push_front(__pt); 24150b57cec5SDimitry Andric } 24160b57cec5SDimitry Andric // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer 24170b57cec5SDimitry Andric else if (__base::__map_.size() < __base::__map_.capacity()) 24180b57cec5SDimitry Andric { // we can put the new buffer into the map, but don't shift things around 24190b57cec5SDimitry Andric // until all buffers are allocated. If we throw, we don't need to fix 24200b57cec5SDimitry Andric // anything up (any added buffers are undetectible) 24210b57cec5SDimitry Andric if (__base::__map_.__front_spare() > 0) 24220b57cec5SDimitry Andric __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 24230b57cec5SDimitry Andric else 24240b57cec5SDimitry Andric { 24250b57cec5SDimitry Andric __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 24260b57cec5SDimitry Andric // Done allocating, reorder capacity 24270b57cec5SDimitry Andric pointer __pt = __base::__map_.back(); 24280b57cec5SDimitry Andric __base::__map_.pop_back(); 24290b57cec5SDimitry Andric __base::__map_.push_front(__pt); 24300b57cec5SDimitry Andric } 24310b57cec5SDimitry Andric __base::__start_ = __base::__map_.size() == 1 ? 24320b57cec5SDimitry Andric __base::__block_size / 2 : 24330b57cec5SDimitry Andric __base::__start_ + __base::__block_size; 24340b57cec5SDimitry Andric } 24350b57cec5SDimitry Andric // Else need to allocate 1 buffer, *and* we need to reallocate __map_. 24360b57cec5SDimitry Andric else 24370b57cec5SDimitry Andric { 24380b57cec5SDimitry Andric __split_buffer<pointer, typename __base::__pointer_allocator&> 24390b57cec5SDimitry Andric __buf(max<size_type>(2 * __base::__map_.capacity(), 1), 24400b57cec5SDimitry Andric 0, __base::__map_.__alloc()); 24410b57cec5SDimitry Andric 24420b57cec5SDimitry Andric typedef __allocator_destructor<_Allocator> _Dp; 24430b57cec5SDimitry Andric unique_ptr<pointer, _Dp> __hold( 24440b57cec5SDimitry Andric __alloc_traits::allocate(__a, __base::__block_size), 24450b57cec5SDimitry Andric _Dp(__a, __base::__block_size)); 24460b57cec5SDimitry Andric __buf.push_back(__hold.get()); 24470b57cec5SDimitry Andric __hold.release(); 24480b57cec5SDimitry Andric 24490b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __base::__map_.begin(); 24500b57cec5SDimitry Andric __i != __base::__map_.end(); ++__i) 24510b57cec5SDimitry Andric __buf.push_back(*__i); 24520b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__first_, __buf.__first_); 24530b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 24540b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_, __buf.__end_); 24550b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 24560b57cec5SDimitry Andric __base::__start_ = __base::__map_.size() == 1 ? 24570b57cec5SDimitry Andric __base::__block_size / 2 : 24580b57cec5SDimitry Andric __base::__start_ + __base::__block_size; 24590b57cec5SDimitry Andric } 24600b57cec5SDimitry Andric} 24610b57cec5SDimitry Andric 24620b57cec5SDimitry Andric// Create front capacity for __n elements. 24630b57cec5SDimitry Andric// Strong guarantee. Either do it or don't touch anything. 24640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 24650b57cec5SDimitry Andricvoid 24660b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__add_front_capacity(size_type __n) 24670b57cec5SDimitry Andric{ 24680b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 24690b57cec5SDimitry Andric size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); 24700b57cec5SDimitry Andric // Number of unused blocks at back: 24710b57cec5SDimitry Andric size_type __back_capacity = __back_spare() / __base::__block_size; 24720b57cec5SDimitry Andric __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need 24730b57cec5SDimitry Andric __nb -= __back_capacity; // number of blocks need to allocate 24740b57cec5SDimitry Andric // If __nb == 0, then we have sufficient capacity. 24750b57cec5SDimitry Andric if (__nb == 0) 24760b57cec5SDimitry Andric { 24770b57cec5SDimitry Andric __base::__start_ += __base::__block_size * __back_capacity; 24780b57cec5SDimitry Andric for (; __back_capacity > 0; --__back_capacity) 24790b57cec5SDimitry Andric { 24800b57cec5SDimitry Andric pointer __pt = __base::__map_.back(); 24810b57cec5SDimitry Andric __base::__map_.pop_back(); 24820b57cec5SDimitry Andric __base::__map_.push_front(__pt); 24830b57cec5SDimitry Andric } 24840b57cec5SDimitry Andric } 24850b57cec5SDimitry Andric // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 24860b57cec5SDimitry Andric else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) 24870b57cec5SDimitry Andric { // we can put the new buffers into the map, but don't shift things around 24880b57cec5SDimitry Andric // until all buffers are allocated. If we throw, we don't need to fix 24890b57cec5SDimitry Andric // anything up (any added buffers are undetectible) 24900b57cec5SDimitry Andric for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) 24910b57cec5SDimitry Andric { 24920b57cec5SDimitry Andric if (__base::__map_.__front_spare() == 0) 24930b57cec5SDimitry Andric break; 24940b57cec5SDimitry Andric __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 24950b57cec5SDimitry Andric } 24960b57cec5SDimitry Andric for (; __nb > 0; --__nb, ++__back_capacity) 24970b57cec5SDimitry Andric __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 24980b57cec5SDimitry Andric // Done allocating, reorder capacity 24990b57cec5SDimitry Andric __base::__start_ += __back_capacity * __base::__block_size; 25000b57cec5SDimitry Andric for (; __back_capacity > 0; --__back_capacity) 25010b57cec5SDimitry Andric { 25020b57cec5SDimitry Andric pointer __pt = __base::__map_.back(); 25030b57cec5SDimitry Andric __base::__map_.pop_back(); 25040b57cec5SDimitry Andric __base::__map_.push_front(__pt); 25050b57cec5SDimitry Andric } 25060b57cec5SDimitry Andric } 25070b57cec5SDimitry Andric // Else need to allocate __nb buffers, *and* we need to reallocate __map_. 25080b57cec5SDimitry Andric else 25090b57cec5SDimitry Andric { 25100b57cec5SDimitry Andric size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); 25110b57cec5SDimitry Andric __split_buffer<pointer, typename __base::__pointer_allocator&> 25120b57cec5SDimitry Andric __buf(max<size_type>(2* __base::__map_.capacity(), 25130b57cec5SDimitry Andric __nb + __base::__map_.size()), 25140b57cec5SDimitry Andric 0, __base::__map_.__alloc()); 25150b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25160b57cec5SDimitry Andric try 25170b57cec5SDimitry Andric { 25180b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25190b57cec5SDimitry Andric for (; __nb > 0; --__nb) 25200b57cec5SDimitry Andric __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 25210b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25220b57cec5SDimitry Andric } 25230b57cec5SDimitry Andric catch (...) 25240b57cec5SDimitry Andric { 25250b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __buf.begin(); 25260b57cec5SDimitry Andric __i != __buf.end(); ++__i) 25270b57cec5SDimitry Andric __alloc_traits::deallocate(__a, *__i, __base::__block_size); 25280b57cec5SDimitry Andric throw; 25290b57cec5SDimitry Andric } 25300b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25310b57cec5SDimitry Andric for (; __back_capacity > 0; --__back_capacity) 25320b57cec5SDimitry Andric { 25330b57cec5SDimitry Andric __buf.push_back(__base::__map_.back()); 25340b57cec5SDimitry Andric __base::__map_.pop_back(); 25350b57cec5SDimitry Andric } 25360b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __base::__map_.begin(); 25370b57cec5SDimitry Andric __i != __base::__map_.end(); ++__i) 25380b57cec5SDimitry Andric __buf.push_back(*__i); 25390b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__first_, __buf.__first_); 25400b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 25410b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_, __buf.__end_); 25420b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 25430b57cec5SDimitry Andric __base::__start_ += __ds; 25440b57cec5SDimitry Andric } 25450b57cec5SDimitry Andric} 25460b57cec5SDimitry Andric 25470b57cec5SDimitry Andric// Create back capacity for one block of elements. 25480b57cec5SDimitry Andric// Strong guarantee. Either do it or don't touch anything. 25490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 25500b57cec5SDimitry Andricvoid 25510b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__add_back_capacity() 25520b57cec5SDimitry Andric{ 25530b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 25540b57cec5SDimitry Andric if (__front_spare() >= __base::__block_size) 25550b57cec5SDimitry Andric { 25560b57cec5SDimitry Andric __base::__start_ -= __base::__block_size; 25570b57cec5SDimitry Andric pointer __pt = __base::__map_.front(); 25580b57cec5SDimitry Andric __base::__map_.pop_front(); 25590b57cec5SDimitry Andric __base::__map_.push_back(__pt); 25600b57cec5SDimitry Andric } 25610b57cec5SDimitry Andric // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 25620b57cec5SDimitry Andric else if (__base::__map_.size() < __base::__map_.capacity()) 25630b57cec5SDimitry Andric { // we can put the new buffer into the map, but don't shift things around 25640b57cec5SDimitry Andric // until it is allocated. If we throw, we don't need to fix 25650b57cec5SDimitry Andric // anything up (any added buffers are undetectible) 25660b57cec5SDimitry Andric if (__base::__map_.__back_spare() != 0) 25670b57cec5SDimitry Andric __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 25680b57cec5SDimitry Andric else 25690b57cec5SDimitry Andric { 25700b57cec5SDimitry Andric __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 25710b57cec5SDimitry Andric // Done allocating, reorder capacity 25720b57cec5SDimitry Andric pointer __pt = __base::__map_.front(); 25730b57cec5SDimitry Andric __base::__map_.pop_front(); 25740b57cec5SDimitry Andric __base::__map_.push_back(__pt); 25750b57cec5SDimitry Andric } 25760b57cec5SDimitry Andric } 25770b57cec5SDimitry Andric // Else need to allocate 1 buffer, *and* we need to reallocate __map_. 25780b57cec5SDimitry Andric else 25790b57cec5SDimitry Andric { 25800b57cec5SDimitry Andric __split_buffer<pointer, typename __base::__pointer_allocator&> 25810b57cec5SDimitry Andric __buf(max<size_type>(2* __base::__map_.capacity(), 1), 25820b57cec5SDimitry Andric __base::__map_.size(), 25830b57cec5SDimitry Andric __base::__map_.__alloc()); 25840b57cec5SDimitry Andric 25850b57cec5SDimitry Andric typedef __allocator_destructor<_Allocator> _Dp; 25860b57cec5SDimitry Andric unique_ptr<pointer, _Dp> __hold( 25870b57cec5SDimitry Andric __alloc_traits::allocate(__a, __base::__block_size), 25880b57cec5SDimitry Andric _Dp(__a, __base::__block_size)); 25890b57cec5SDimitry Andric __buf.push_back(__hold.get()); 25900b57cec5SDimitry Andric __hold.release(); 25910b57cec5SDimitry Andric 25920b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __base::__map_.end(); 25930b57cec5SDimitry Andric __i != __base::__map_.begin();) 25940b57cec5SDimitry Andric __buf.push_front(*--__i); 25950b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__first_, __buf.__first_); 25960b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 25970b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_, __buf.__end_); 25980b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 25990b57cec5SDimitry Andric } 26000b57cec5SDimitry Andric} 26010b57cec5SDimitry Andric 26020b57cec5SDimitry Andric// Create back capacity for __n elements. 26030b57cec5SDimitry Andric// Strong guarantee. Either do it or don't touch anything. 26040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 26050b57cec5SDimitry Andricvoid 26060b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__add_back_capacity(size_type __n) 26070b57cec5SDimitry Andric{ 26080b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 26090b57cec5SDimitry Andric size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); 26100b57cec5SDimitry Andric // Number of unused blocks at front: 26110b57cec5SDimitry Andric size_type __front_capacity = __front_spare() / __base::__block_size; 26120b57cec5SDimitry Andric __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need 26130b57cec5SDimitry Andric __nb -= __front_capacity; // number of blocks need to allocate 26140b57cec5SDimitry Andric // If __nb == 0, then we have sufficient capacity. 26150b57cec5SDimitry Andric if (__nb == 0) 26160b57cec5SDimitry Andric { 26170b57cec5SDimitry Andric __base::__start_ -= __base::__block_size * __front_capacity; 26180b57cec5SDimitry Andric for (; __front_capacity > 0; --__front_capacity) 26190b57cec5SDimitry Andric { 26200b57cec5SDimitry Andric pointer __pt = __base::__map_.front(); 26210b57cec5SDimitry Andric __base::__map_.pop_front(); 26220b57cec5SDimitry Andric __base::__map_.push_back(__pt); 26230b57cec5SDimitry Andric } 26240b57cec5SDimitry Andric } 26250b57cec5SDimitry Andric // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 26260b57cec5SDimitry Andric else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) 26270b57cec5SDimitry Andric { // we can put the new buffers into the map, but don't shift things around 26280b57cec5SDimitry Andric // until all buffers are allocated. If we throw, we don't need to fix 26290b57cec5SDimitry Andric // anything up (any added buffers are undetectible) 26300b57cec5SDimitry Andric for (; __nb > 0; --__nb) 26310b57cec5SDimitry Andric { 26320b57cec5SDimitry Andric if (__base::__map_.__back_spare() == 0) 26330b57cec5SDimitry Andric break; 26340b57cec5SDimitry Andric __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 26350b57cec5SDimitry Andric } 26360b57cec5SDimitry Andric for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += 26370b57cec5SDimitry Andric __base::__block_size - (__base::__map_.size() == 1)) 26380b57cec5SDimitry Andric __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 26390b57cec5SDimitry Andric // Done allocating, reorder capacity 26400b57cec5SDimitry Andric __base::__start_ -= __base::__block_size * __front_capacity; 26410b57cec5SDimitry Andric for (; __front_capacity > 0; --__front_capacity) 26420b57cec5SDimitry Andric { 26430b57cec5SDimitry Andric pointer __pt = __base::__map_.front(); 26440b57cec5SDimitry Andric __base::__map_.pop_front(); 26450b57cec5SDimitry Andric __base::__map_.push_back(__pt); 26460b57cec5SDimitry Andric } 26470b57cec5SDimitry Andric } 26480b57cec5SDimitry Andric // Else need to allocate __nb buffers, *and* we need to reallocate __map_. 26490b57cec5SDimitry Andric else 26500b57cec5SDimitry Andric { 26510b57cec5SDimitry Andric size_type __ds = __front_capacity * __base::__block_size; 26520b57cec5SDimitry Andric __split_buffer<pointer, typename __base::__pointer_allocator&> 26530b57cec5SDimitry Andric __buf(max<size_type>(2* __base::__map_.capacity(), 26540b57cec5SDimitry Andric __nb + __base::__map_.size()), 26550b57cec5SDimitry Andric __base::__map_.size() - __front_capacity, 26560b57cec5SDimitry Andric __base::__map_.__alloc()); 26570b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 26580b57cec5SDimitry Andric try 26590b57cec5SDimitry Andric { 26600b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26610b57cec5SDimitry Andric for (; __nb > 0; --__nb) 26620b57cec5SDimitry Andric __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 26630b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 26640b57cec5SDimitry Andric } 26650b57cec5SDimitry Andric catch (...) 26660b57cec5SDimitry Andric { 26670b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __buf.begin(); 26680b57cec5SDimitry Andric __i != __buf.end(); ++__i) 26690b57cec5SDimitry Andric __alloc_traits::deallocate(__a, *__i, __base::__block_size); 26700b57cec5SDimitry Andric throw; 26710b57cec5SDimitry Andric } 26720b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26730b57cec5SDimitry Andric for (; __front_capacity > 0; --__front_capacity) 26740b57cec5SDimitry Andric { 26750b57cec5SDimitry Andric __buf.push_back(__base::__map_.front()); 26760b57cec5SDimitry Andric __base::__map_.pop_front(); 26770b57cec5SDimitry Andric } 26780b57cec5SDimitry Andric for (typename __base::__map_pointer __i = __base::__map_.end(); 26790b57cec5SDimitry Andric __i != __base::__map_.begin();) 26800b57cec5SDimitry Andric __buf.push_front(*--__i); 26810b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__first_, __buf.__first_); 26820b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 26830b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_, __buf.__end_); 26840b57cec5SDimitry Andric _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 26850b57cec5SDimitry Andric __base::__start_ -= __ds; 26860b57cec5SDimitry Andric } 26870b57cec5SDimitry Andric} 26880b57cec5SDimitry Andric 26890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 26900b57cec5SDimitry Andricvoid 26910b57cec5SDimitry Andricdeque<_Tp, _Allocator>::pop_front() 26920b57cec5SDimitry Andric{ 26930b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 2694e8d8bef9SDimitry Andric __alloc_traits::destroy(__a, _VSTD::__to_address(*(__base::__map_.begin() + 26950b57cec5SDimitry Andric __base::__start_ / __base::__block_size) + 26960b57cec5SDimitry Andric __base::__start_ % __base::__block_size)); 26970b57cec5SDimitry Andric --__base::size(); 2698e40139ffSDimitry Andric ++__base::__start_; 2699e40139ffSDimitry Andric __maybe_remove_front_spare(); 27000b57cec5SDimitry Andric} 27010b57cec5SDimitry Andric 27020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 27030b57cec5SDimitry Andricvoid 27040b57cec5SDimitry Andricdeque<_Tp, _Allocator>::pop_back() 27050b57cec5SDimitry Andric{ 2706fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "deque::pop_back called on an empty deque"); 27070b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 27080b57cec5SDimitry Andric size_type __p = __base::size() + __base::__start_ - 1; 2709e8d8bef9SDimitry Andric __alloc_traits::destroy(__a, _VSTD::__to_address(*(__base::__map_.begin() + 27100b57cec5SDimitry Andric __p / __base::__block_size) + 27110b57cec5SDimitry Andric __p % __base::__block_size)); 27120b57cec5SDimitry Andric --__base::size(); 2713e40139ffSDimitry Andric __maybe_remove_back_spare(); 27140b57cec5SDimitry Andric} 27150b57cec5SDimitry Andric 27160b57cec5SDimitry Andric// move assign [__f, __l) to [__r, __r + (__l-__f)). 27170b57cec5SDimitry Andric// If __vt points into [__f, __l), then subtract (__f - __r) from __vt. 27180b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 27190b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 27200b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, 27210b57cec5SDimitry Andric const_pointer& __vt) 27220b57cec5SDimitry Andric{ 27230b57cec5SDimitry Andric // as if 27240b57cec5SDimitry Andric // for (; __f != __l; ++__f, ++__r) 27250b57cec5SDimitry Andric // *__r = _VSTD::move(*__f); 27260b57cec5SDimitry Andric difference_type __n = __l - __f; 27270b57cec5SDimitry Andric while (__n > 0) 27280b57cec5SDimitry Andric { 27290b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 27300b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __base::__block_size; 27310b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 27320b57cec5SDimitry Andric if (__bs > __n) 27330b57cec5SDimitry Andric { 27340b57cec5SDimitry Andric __bs = __n; 27350b57cec5SDimitry Andric __fe = __fb + __bs; 27360b57cec5SDimitry Andric } 27370b57cec5SDimitry Andric if (__fb <= __vt && __vt < __fe) 27380b57cec5SDimitry Andric __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; 27390b57cec5SDimitry Andric __r = _VSTD::move(__fb, __fe, __r); 27400b57cec5SDimitry Andric __n -= __bs; 27410b57cec5SDimitry Andric __f += __bs; 27420b57cec5SDimitry Andric } 27430b57cec5SDimitry Andric return __r; 27440b57cec5SDimitry Andric} 27450b57cec5SDimitry Andric 27460b57cec5SDimitry Andric// move assign [__f, __l) to [__r - (__l-__f), __r) backwards. 27470b57cec5SDimitry Andric// If __vt points into [__f, __l), then add (__r - __l) to __vt. 27480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 27490b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 27500b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, 27510b57cec5SDimitry Andric const_pointer& __vt) 27520b57cec5SDimitry Andric{ 27530b57cec5SDimitry Andric // as if 27540b57cec5SDimitry Andric // while (__f != __l) 27550b57cec5SDimitry Andric // *--__r = _VSTD::move(*--__l); 27560b57cec5SDimitry Andric difference_type __n = __l - __f; 27570b57cec5SDimitry Andric while (__n > 0) 27580b57cec5SDimitry Andric { 27590b57cec5SDimitry Andric --__l; 27600b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 27610b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 27620b57cec5SDimitry Andric difference_type __bs = __le - __lb; 27630b57cec5SDimitry Andric if (__bs > __n) 27640b57cec5SDimitry Andric { 27650b57cec5SDimitry Andric __bs = __n; 27660b57cec5SDimitry Andric __lb = __le - __bs; 27670b57cec5SDimitry Andric } 27680b57cec5SDimitry Andric if (__lb <= __vt && __vt < __le) 27690b57cec5SDimitry Andric __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; 27700b57cec5SDimitry Andric __r = _VSTD::move_backward(__lb, __le, __r); 27710b57cec5SDimitry Andric __n -= __bs; 27720b57cec5SDimitry Andric __l -= __bs - 1; 27730b57cec5SDimitry Andric } 27740b57cec5SDimitry Andric return __r; 27750b57cec5SDimitry Andric} 27760b57cec5SDimitry Andric 27770b57cec5SDimitry Andric// move construct [__f, __l) to [__r, __r + (__l-__f)). 27780b57cec5SDimitry Andric// If __vt points into [__f, __l), then add (__r - __f) to __vt. 27790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 27800b57cec5SDimitry Andricvoid 27810b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, 27820b57cec5SDimitry Andric iterator __r, const_pointer& __vt) 27830b57cec5SDimitry Andric{ 27840b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 27850b57cec5SDimitry Andric // as if 27860b57cec5SDimitry Andric // for (; __f != __l; ++__r, ++__f, ++__base::size()) 27870b57cec5SDimitry Andric // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); 27880b57cec5SDimitry Andric difference_type __n = __l - __f; 27890b57cec5SDimitry Andric while (__n > 0) 27900b57cec5SDimitry Andric { 27910b57cec5SDimitry Andric pointer __fb = __f.__ptr_; 27920b57cec5SDimitry Andric pointer __fe = *__f.__m_iter_ + __base::__block_size; 27930b57cec5SDimitry Andric difference_type __bs = __fe - __fb; 27940b57cec5SDimitry Andric if (__bs > __n) 27950b57cec5SDimitry Andric { 27960b57cec5SDimitry Andric __bs = __n; 27970b57cec5SDimitry Andric __fe = __fb + __bs; 27980b57cec5SDimitry Andric } 27990b57cec5SDimitry Andric if (__fb <= __vt && __vt < __fe) 28000b57cec5SDimitry Andric __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; 28010b57cec5SDimitry Andric for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) 28020b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); 28030b57cec5SDimitry Andric __n -= __bs; 28040b57cec5SDimitry Andric __f += __bs; 28050b57cec5SDimitry Andric } 28060b57cec5SDimitry Andric} 28070b57cec5SDimitry Andric 28080b57cec5SDimitry Andric// move construct [__f, __l) to [__r - (__l-__f), __r) backwards. 28090b57cec5SDimitry Andric// If __vt points into [__f, __l), then subtract (__l - __r) from __vt. 28100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 28110b57cec5SDimitry Andricvoid 28120b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, 28130b57cec5SDimitry Andric iterator __r, const_pointer& __vt) 28140b57cec5SDimitry Andric{ 28150b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 28160b57cec5SDimitry Andric // as if 28170b57cec5SDimitry Andric // for (iterator __j = __l; __j != __f;) 28180b57cec5SDimitry Andric // { 28190b57cec5SDimitry Andric // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); 28200b57cec5SDimitry Andric // --__base::__start_; 28210b57cec5SDimitry Andric // ++__base::size(); 28220b57cec5SDimitry Andric // } 28230b57cec5SDimitry Andric difference_type __n = __l - __f; 28240b57cec5SDimitry Andric while (__n > 0) 28250b57cec5SDimitry Andric { 28260b57cec5SDimitry Andric --__l; 28270b57cec5SDimitry Andric pointer __lb = *__l.__m_iter_; 28280b57cec5SDimitry Andric pointer __le = __l.__ptr_ + 1; 28290b57cec5SDimitry Andric difference_type __bs = __le - __lb; 28300b57cec5SDimitry Andric if (__bs > __n) 28310b57cec5SDimitry Andric { 28320b57cec5SDimitry Andric __bs = __n; 28330b57cec5SDimitry Andric __lb = __le - __bs; 28340b57cec5SDimitry Andric } 28350b57cec5SDimitry Andric if (__lb <= __vt && __vt < __le) 28360b57cec5SDimitry Andric __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; 28370b57cec5SDimitry Andric while (__le != __lb) 28380b57cec5SDimitry Andric { 28390b57cec5SDimitry Andric __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); 28400b57cec5SDimitry Andric --__base::__start_; 28410b57cec5SDimitry Andric ++__base::size(); 28420b57cec5SDimitry Andric } 28430b57cec5SDimitry Andric __n -= __bs; 28440b57cec5SDimitry Andric __l -= __bs - 1; 28450b57cec5SDimitry Andric } 28460b57cec5SDimitry Andric} 28470b57cec5SDimitry Andric 28480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 28490b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 28500b57cec5SDimitry Andricdeque<_Tp, _Allocator>::erase(const_iterator __f) 28510b57cec5SDimitry Andric{ 28520b57cec5SDimitry Andric iterator __b = __base::begin(); 28530b57cec5SDimitry Andric difference_type __pos = __f - __b; 28540b57cec5SDimitry Andric iterator __p = __b + __pos; 28550b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 28560b57cec5SDimitry Andric if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2) 28570b57cec5SDimitry Andric { // erase from front 28580b57cec5SDimitry Andric _VSTD::move_backward(__b, __p, _VSTD::next(__p)); 28590b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); 28600b57cec5SDimitry Andric --__base::size(); 28610b57cec5SDimitry Andric ++__base::__start_; 2862e40139ffSDimitry Andric __maybe_remove_front_spare(); 28630b57cec5SDimitry Andric } 28640b57cec5SDimitry Andric else 28650b57cec5SDimitry Andric { // erase from back 28660b57cec5SDimitry Andric iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); 28670b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 28680b57cec5SDimitry Andric --__base::size(); 2869e40139ffSDimitry Andric __maybe_remove_back_spare(); 28700b57cec5SDimitry Andric } 28710b57cec5SDimitry Andric return __base::begin() + __pos; 28720b57cec5SDimitry Andric} 28730b57cec5SDimitry Andric 28740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 28750b57cec5SDimitry Andrictypename deque<_Tp, _Allocator>::iterator 28760b57cec5SDimitry Andricdeque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) 28770b57cec5SDimitry Andric{ 28780b57cec5SDimitry Andric difference_type __n = __l - __f; 28790b57cec5SDimitry Andric iterator __b = __base::begin(); 28800b57cec5SDimitry Andric difference_type __pos = __f - __b; 28810b57cec5SDimitry Andric iterator __p = __b + __pos; 28820b57cec5SDimitry Andric if (__n > 0) 28830b57cec5SDimitry Andric { 28840b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 28850b57cec5SDimitry Andric if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2) 28860b57cec5SDimitry Andric { // erase from front 28870b57cec5SDimitry Andric iterator __i = _VSTD::move_backward(__b, __p, __p + __n); 28880b57cec5SDimitry Andric for (; __b != __i; ++__b) 28890b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); 28900b57cec5SDimitry Andric __base::size() -= __n; 28910b57cec5SDimitry Andric __base::__start_ += __n; 2892e40139ffSDimitry Andric while (__maybe_remove_front_spare()) { 28930b57cec5SDimitry Andric } 28940b57cec5SDimitry Andric } 28950b57cec5SDimitry Andric else 28960b57cec5SDimitry Andric { // erase from back 28970b57cec5SDimitry Andric iterator __i = _VSTD::move(__p + __n, __base::end(), __p); 28980b57cec5SDimitry Andric for (iterator __e = __base::end(); __i != __e; ++__i) 28990b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 29000b57cec5SDimitry Andric __base::size() -= __n; 2901e40139ffSDimitry Andric while (__maybe_remove_back_spare()) { 29020b57cec5SDimitry Andric } 29030b57cec5SDimitry Andric } 29040b57cec5SDimitry Andric } 29050b57cec5SDimitry Andric return __base::begin() + __pos; 29060b57cec5SDimitry Andric} 29070b57cec5SDimitry Andric 29080b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29090b57cec5SDimitry Andricvoid 29100b57cec5SDimitry Andricdeque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) 29110b57cec5SDimitry Andric{ 29120b57cec5SDimitry Andric iterator __e = __base::end(); 29130b57cec5SDimitry Andric difference_type __n = __e - __f; 29140b57cec5SDimitry Andric if (__n > 0) 29150b57cec5SDimitry Andric { 29160b57cec5SDimitry Andric allocator_type& __a = __base::__alloc(); 29170b57cec5SDimitry Andric iterator __b = __base::begin(); 29180b57cec5SDimitry Andric difference_type __pos = __f - __b; 29190b57cec5SDimitry Andric for (iterator __p = __b + __pos; __p != __e; ++__p) 29200b57cec5SDimitry Andric __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); 29210b57cec5SDimitry Andric __base::size() -= __n; 2922e40139ffSDimitry Andric while (__maybe_remove_back_spare()) { 29230b57cec5SDimitry Andric } 29240b57cec5SDimitry Andric } 29250b57cec5SDimitry Andric} 29260b57cec5SDimitry Andric 29270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29280b57cec5SDimitry Andricinline 29290b57cec5SDimitry Andricvoid 29300b57cec5SDimitry Andricdeque<_Tp, _Allocator>::swap(deque& __c) 29310b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 29320b57cec5SDimitry Andric _NOEXCEPT 29330b57cec5SDimitry Andric#else 29340b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 29350b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 29360b57cec5SDimitry Andric#endif 29370b57cec5SDimitry Andric{ 29380b57cec5SDimitry Andric __base::swap(__c); 29390b57cec5SDimitry Andric} 29400b57cec5SDimitry Andric 29410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29420b57cec5SDimitry Andricinline 29430b57cec5SDimitry Andricvoid 29440b57cec5SDimitry Andricdeque<_Tp, _Allocator>::clear() _NOEXCEPT 29450b57cec5SDimitry Andric{ 29460b57cec5SDimitry Andric __base::clear(); 29470b57cec5SDimitry Andric} 29480b57cec5SDimitry Andric 29490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29510b57cec5SDimitry Andricbool 29520b57cec5SDimitry Andricoperator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29530b57cec5SDimitry Andric{ 29540b57cec5SDimitry Andric const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); 29550b57cec5SDimitry Andric return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 29560b57cec5SDimitry Andric} 29570b57cec5SDimitry Andric 29580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29600b57cec5SDimitry Andricbool 29610b57cec5SDimitry Andricoperator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29620b57cec5SDimitry Andric{ 29630b57cec5SDimitry Andric return !(__x == __y); 29640b57cec5SDimitry Andric} 29650b57cec5SDimitry Andric 29660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29680b57cec5SDimitry Andricbool 29690b57cec5SDimitry Andricoperator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29700b57cec5SDimitry Andric{ 29710b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 29720b57cec5SDimitry Andric} 29730b57cec5SDimitry Andric 29740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29760b57cec5SDimitry Andricbool 29770b57cec5SDimitry Andricoperator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29780b57cec5SDimitry Andric{ 29790b57cec5SDimitry Andric return __y < __x; 29800b57cec5SDimitry Andric} 29810b57cec5SDimitry Andric 29820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29840b57cec5SDimitry Andricbool 29850b57cec5SDimitry Andricoperator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29860b57cec5SDimitry Andric{ 29870b57cec5SDimitry Andric return !(__x < __y); 29880b57cec5SDimitry Andric} 29890b57cec5SDimitry Andric 29900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29920b57cec5SDimitry Andricbool 29930b57cec5SDimitry Andricoperator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 29940b57cec5SDimitry Andric{ 29950b57cec5SDimitry Andric return !(__y < __x); 29960b57cec5SDimitry Andric} 29970b57cec5SDimitry Andric 29980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 29990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 30000b57cec5SDimitry Andricvoid 30010b57cec5SDimitry Andricswap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) 30020b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 30030b57cec5SDimitry Andric{ 30040b57cec5SDimitry Andric __x.swap(__y); 30050b57cec5SDimitry Andric} 30060b57cec5SDimitry Andric 30070b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 30080b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 30095ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type 30105ffd83dbSDimitry Andricerase(deque<_Tp, _Allocator>& __c, const _Up& __v) { 30115ffd83dbSDimitry Andric auto __old_size = __c.size(); 30125ffd83dbSDimitry Andric __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); 30135ffd83dbSDimitry Andric return __old_size - __c.size(); 30145ffd83dbSDimitry Andric} 30150b57cec5SDimitry Andric 30160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 30175ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type 30185ffd83dbSDimitry Andricerase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) { 30195ffd83dbSDimitry Andric auto __old_size = __c.size(); 30205ffd83dbSDimitry Andric __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 30215ffd83dbSDimitry Andric return __old_size - __c.size(); 30225ffd83dbSDimitry Andric} 30230b57cec5SDimitry Andric#endif 30240b57cec5SDimitry Andric 30250b57cec5SDimitry Andric 30260b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 30270b57cec5SDimitry Andric 30280b57cec5SDimitry Andric_LIBCPP_POP_MACROS 30290b57cec5SDimitry Andric 30300b57cec5SDimitry Andric#endif // _LIBCPP_DEQUE 3031