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