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