14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===---------------------------- deque -----------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_DEQUE 124684ddb6SLionel Sambuc#define _LIBCPP_DEQUE 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc deque synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambuctemplate <class T, class Allocator = allocator<T> > 214684ddb6SLionel Sambucclass deque 224684ddb6SLionel Sambuc{ 234684ddb6SLionel Sambucpublic: 244684ddb6SLionel Sambuc // types: 254684ddb6SLionel Sambuc typedef T value_type; 264684ddb6SLionel Sambuc typedef Allocator allocator_type; 274684ddb6SLionel Sambuc 284684ddb6SLionel Sambuc typedef typename allocator_type::reference reference; 294684ddb6SLionel Sambuc typedef typename allocator_type::const_reference const_reference; 304684ddb6SLionel Sambuc typedef implementation-defined iterator; 314684ddb6SLionel Sambuc typedef implementation-defined const_iterator; 324684ddb6SLionel Sambuc typedef typename allocator_type::size_type size_type; 334684ddb6SLionel Sambuc typedef typename allocator_type::difference_type difference_type; 344684ddb6SLionel Sambuc 354684ddb6SLionel Sambuc typedef typename allocator_type::pointer pointer; 364684ddb6SLionel Sambuc typedef typename allocator_type::const_pointer const_pointer; 374684ddb6SLionel Sambuc typedef std::reverse_iterator<iterator> reverse_iterator; 384684ddb6SLionel Sambuc typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 394684ddb6SLionel Sambuc 404684ddb6SLionel Sambuc // construct/copy/destroy: 414684ddb6SLionel Sambuc deque() noexcept(is_nothrow_default_constructible<allocator_type>::value); 424684ddb6SLionel Sambuc explicit deque(const allocator_type& a); 434684ddb6SLionel Sambuc explicit deque(size_type n); 444684ddb6SLionel Sambuc explicit deque(size_type n, const allocator_type& a); // C++14 454684ddb6SLionel Sambuc deque(size_type n, const value_type& v); 464684ddb6SLionel Sambuc deque(size_type n, const value_type& v, const allocator_type& a); 474684ddb6SLionel Sambuc template <class InputIterator> 484684ddb6SLionel Sambuc deque(InputIterator f, InputIterator l); 494684ddb6SLionel Sambuc template <class InputIterator> 504684ddb6SLionel Sambuc deque(InputIterator f, InputIterator l, const allocator_type& a); 514684ddb6SLionel Sambuc deque(const deque& c); 524684ddb6SLionel Sambuc deque(deque&& c) 534684ddb6SLionel Sambuc noexcept(is_nothrow_move_constructible<allocator_type>::value); 544684ddb6SLionel Sambuc deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); 554684ddb6SLionel Sambuc deque(const deque& c, const allocator_type& a); 564684ddb6SLionel Sambuc deque(deque&& c, const allocator_type& a); 574684ddb6SLionel Sambuc ~deque(); 584684ddb6SLionel Sambuc 594684ddb6SLionel Sambuc deque& operator=(const deque& c); 604684ddb6SLionel Sambuc deque& operator=(deque&& c) 614684ddb6SLionel Sambuc noexcept( 624684ddb6SLionel Sambuc allocator_type::propagate_on_container_move_assignment::value && 634684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value); 644684ddb6SLionel Sambuc deque& operator=(initializer_list<value_type> il); 654684ddb6SLionel Sambuc 664684ddb6SLionel Sambuc template <class InputIterator> 674684ddb6SLionel Sambuc void assign(InputIterator f, InputIterator l); 684684ddb6SLionel Sambuc void assign(size_type n, const value_type& v); 694684ddb6SLionel Sambuc void assign(initializer_list<value_type> il); 704684ddb6SLionel Sambuc 714684ddb6SLionel Sambuc allocator_type get_allocator() const noexcept; 724684ddb6SLionel Sambuc 734684ddb6SLionel Sambuc // iterators: 744684ddb6SLionel Sambuc 754684ddb6SLionel Sambuc iterator begin() noexcept; 764684ddb6SLionel Sambuc const_iterator begin() const noexcept; 774684ddb6SLionel Sambuc iterator end() noexcept; 784684ddb6SLionel Sambuc const_iterator end() const noexcept; 794684ddb6SLionel Sambuc 804684ddb6SLionel Sambuc reverse_iterator rbegin() noexcept; 814684ddb6SLionel Sambuc const_reverse_iterator rbegin() const noexcept; 824684ddb6SLionel Sambuc reverse_iterator rend() noexcept; 834684ddb6SLionel Sambuc const_reverse_iterator rend() const noexcept; 844684ddb6SLionel Sambuc 854684ddb6SLionel Sambuc const_iterator cbegin() const noexcept; 864684ddb6SLionel Sambuc const_iterator cend() const noexcept; 874684ddb6SLionel Sambuc const_reverse_iterator crbegin() const noexcept; 884684ddb6SLionel Sambuc const_reverse_iterator crend() const noexcept; 894684ddb6SLionel Sambuc 904684ddb6SLionel Sambuc // capacity: 914684ddb6SLionel Sambuc size_type size() const noexcept; 924684ddb6SLionel Sambuc size_type max_size() const noexcept; 934684ddb6SLionel Sambuc void resize(size_type n); 944684ddb6SLionel Sambuc void resize(size_type n, const value_type& v); 954684ddb6SLionel Sambuc void shrink_to_fit(); 964684ddb6SLionel Sambuc bool empty() const noexcept; 974684ddb6SLionel Sambuc 984684ddb6SLionel Sambuc // element access: 994684ddb6SLionel Sambuc reference operator[](size_type i); 1004684ddb6SLionel Sambuc const_reference operator[](size_type i) const; 1014684ddb6SLionel Sambuc reference at(size_type i); 1024684ddb6SLionel Sambuc const_reference at(size_type i) const; 1034684ddb6SLionel Sambuc reference front(); 1044684ddb6SLionel Sambuc const_reference front() const; 1054684ddb6SLionel Sambuc reference back(); 1064684ddb6SLionel Sambuc const_reference back() const; 1074684ddb6SLionel Sambuc 1084684ddb6SLionel Sambuc // modifiers: 1094684ddb6SLionel Sambuc void push_front(const value_type& v); 1104684ddb6SLionel Sambuc void push_front(value_type&& v); 1114684ddb6SLionel Sambuc void push_back(const value_type& v); 1124684ddb6SLionel Sambuc void push_back(value_type&& v); 1134684ddb6SLionel Sambuc template <class... Args> void emplace_front(Args&&... args); 1144684ddb6SLionel Sambuc template <class... Args> void emplace_back(Args&&... args); 1154684ddb6SLionel Sambuc template <class... Args> iterator emplace(const_iterator p, Args&&... args); 1164684ddb6SLionel Sambuc iterator insert(const_iterator p, const value_type& v); 1174684ddb6SLionel Sambuc iterator insert(const_iterator p, value_type&& v); 1184684ddb6SLionel Sambuc iterator insert(const_iterator p, size_type n, const value_type& v); 1194684ddb6SLionel Sambuc template <class InputIterator> 1204684ddb6SLionel Sambuc iterator insert(const_iterator p, InputIterator f, InputIterator l); 1214684ddb6SLionel Sambuc iterator insert(const_iterator p, initializer_list<value_type> il); 1224684ddb6SLionel Sambuc void pop_front(); 1234684ddb6SLionel Sambuc void pop_back(); 1244684ddb6SLionel Sambuc iterator erase(const_iterator p); 1254684ddb6SLionel Sambuc iterator erase(const_iterator f, const_iterator l); 1264684ddb6SLionel Sambuc void swap(deque& c) 127*0a6a1f1dSLionel Sambuc noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 1284684ddb6SLionel Sambuc void clear() noexcept; 1294684ddb6SLionel Sambuc}; 1304684ddb6SLionel Sambuc 1314684ddb6SLionel Sambuctemplate <class T, class Allocator> 1324684ddb6SLionel Sambuc bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1334684ddb6SLionel Sambuctemplate <class T, class Allocator> 1344684ddb6SLionel Sambuc bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1354684ddb6SLionel Sambuctemplate <class T, class Allocator> 1364684ddb6SLionel Sambuc bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1374684ddb6SLionel Sambuctemplate <class T, class Allocator> 1384684ddb6SLionel Sambuc bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1394684ddb6SLionel Sambuctemplate <class T, class Allocator> 1404684ddb6SLionel Sambuc bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1414684ddb6SLionel Sambuctemplate <class T, class Allocator> 1424684ddb6SLionel Sambuc bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); 1434684ddb6SLionel Sambuc 1444684ddb6SLionel Sambuc// specialized algorithms: 1454684ddb6SLionel Sambuctemplate <class T, class Allocator> 1464684ddb6SLionel Sambuc void swap(deque<T,Allocator>& x, deque<T,Allocator>& y) 1474684ddb6SLionel Sambuc noexcept(noexcept(x.swap(y))); 1484684ddb6SLionel Sambuc 1494684ddb6SLionel Sambuc} // std 1504684ddb6SLionel Sambuc 1514684ddb6SLionel Sambuc*/ 1524684ddb6SLionel Sambuc 1534684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1544684ddb6SLionel Sambuc#pragma GCC system_header 1554684ddb6SLionel Sambuc#endif 1564684ddb6SLionel Sambuc 1574684ddb6SLionel Sambuc#include <__config> 1584684ddb6SLionel Sambuc#include <__split_buffer> 1594684ddb6SLionel Sambuc#include <type_traits> 1604684ddb6SLionel Sambuc#include <initializer_list> 1614684ddb6SLionel Sambuc#include <iterator> 1624684ddb6SLionel Sambuc#include <algorithm> 1634684ddb6SLionel Sambuc#include <stdexcept> 1644684ddb6SLionel Sambuc 1654684ddb6SLionel Sambuc#include <__undef_min_max> 1664684ddb6SLionel Sambuc 1674684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 1684684ddb6SLionel Sambuc 1694684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> class __deque_base; 170*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY deque; 1714684ddb6SLionel Sambuc 1724684ddb6SLionel Sambuctemplate <class _ValueType, class _Pointer, class _Reference, class _MapPointer, 1734684ddb6SLionel Sambuc class _DiffType, _DiffType _BlockSize> 1744684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __deque_iterator; 1754684ddb6SLionel Sambuc 1764684ddb6SLionel Sambuctemplate <class _RAIter, 1774684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 1784684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 1794684ddb6SLionel Sambuccopy(_RAIter __f, 1804684ddb6SLionel Sambuc _RAIter __l, 1814684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 1824684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); 1834684ddb6SLionel Sambuc 1844684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 1854684ddb6SLionel Sambuc class _OutputIterator> 1864684ddb6SLionel Sambuc_OutputIterator 1874684ddb6SLionel Sambuccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 1884684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 1894684ddb6SLionel Sambuc _OutputIterator __r); 1904684ddb6SLionel Sambuc 1914684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 1924684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 1934684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 1944684ddb6SLionel Sambuccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 1954684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 1964684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 1974684ddb6SLionel Sambuc 1984684ddb6SLionel Sambuctemplate <class _RAIter, 1994684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2004684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2014684ddb6SLionel Sambuccopy_backward(_RAIter __f, 2024684ddb6SLionel Sambuc _RAIter __l, 2034684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 2044684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); 2054684ddb6SLionel Sambuc 2064684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2074684ddb6SLionel Sambuc class _OutputIterator> 2084684ddb6SLionel Sambuc_OutputIterator 2094684ddb6SLionel Sambuccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2104684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2114684ddb6SLionel Sambuc _OutputIterator __r); 2124684ddb6SLionel Sambuc 2134684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2144684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2154684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2164684ddb6SLionel Sambuccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2174684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2184684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2194684ddb6SLionel Sambuc 2204684ddb6SLionel Sambuctemplate <class _RAIter, 2214684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2224684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2234684ddb6SLionel Sambucmove(_RAIter __f, 2244684ddb6SLionel Sambuc _RAIter __l, 2254684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 2264684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); 2274684ddb6SLionel Sambuc 2284684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2294684ddb6SLionel Sambuc class _OutputIterator> 2304684ddb6SLionel Sambuc_OutputIterator 2314684ddb6SLionel Sambucmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2324684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2334684ddb6SLionel Sambuc _OutputIterator __r); 2344684ddb6SLionel Sambuc 2354684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2364684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2374684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2384684ddb6SLionel Sambucmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2394684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2404684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2414684ddb6SLionel Sambuc 2424684ddb6SLionel Sambuctemplate <class _RAIter, 2434684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2444684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2454684ddb6SLionel Sambucmove_backward(_RAIter __f, 2464684ddb6SLionel Sambuc _RAIter __l, 2474684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 2484684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); 2494684ddb6SLionel Sambuc 2504684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2514684ddb6SLionel Sambuc class _OutputIterator> 2524684ddb6SLionel Sambuc_OutputIterator 2534684ddb6SLionel Sambucmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2544684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2554684ddb6SLionel Sambuc _OutputIterator __r); 2564684ddb6SLionel Sambuc 2574684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 2584684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 2594684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 2604684ddb6SLionel Sambucmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 2614684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 2624684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 2634684ddb6SLionel Sambuc 2644684ddb6SLionel Sambuctemplate <class _ValueType, class _Pointer, class _Reference, class _MapPointer, 2654684ddb6SLionel Sambuc class _DiffType, _DiffType _BlockSize> 2664684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __deque_iterator 2674684ddb6SLionel Sambuc{ 2684684ddb6SLionel Sambuc typedef _MapPointer __map_iterator; 2694684ddb6SLionel Sambucpublic: 2704684ddb6SLionel Sambuc typedef _Pointer pointer; 2714684ddb6SLionel Sambuc typedef _DiffType difference_type; 2724684ddb6SLionel Sambucprivate: 2734684ddb6SLionel Sambuc __map_iterator __m_iter_; 2744684ddb6SLionel Sambuc pointer __ptr_; 2754684ddb6SLionel Sambuc 2764684ddb6SLionel Sambuc static const difference_type __block_size = _BlockSize; 2774684ddb6SLionel Sambucpublic: 2784684ddb6SLionel Sambuc typedef _ValueType value_type; 2794684ddb6SLionel Sambuc typedef random_access_iterator_tag iterator_category; 2804684ddb6SLionel Sambuc typedef _Reference reference; 2814684ddb6SLionel Sambuc 2824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT 2834684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 2844684ddb6SLionel Sambuc : __m_iter_(nullptr), __ptr_(nullptr) 2854684ddb6SLionel Sambuc#endif 2864684ddb6SLionel Sambuc {} 2874684ddb6SLionel Sambuc 2884684ddb6SLionel Sambuc template <class _Pp, class _Rp, class _MP> 2894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2904684ddb6SLionel Sambuc __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it, 2914684ddb6SLionel Sambuc typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT 2924684ddb6SLionel Sambuc : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} 2934684ddb6SLionel Sambuc 2944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} 2954684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} 2964684ddb6SLionel Sambuc 2974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() 2984684ddb6SLionel Sambuc { 2994684ddb6SLionel Sambuc if (++__ptr_ - *__m_iter_ == __block_size) 3004684ddb6SLionel Sambuc { 3014684ddb6SLionel Sambuc ++__m_iter_; 3024684ddb6SLionel Sambuc __ptr_ = *__m_iter_; 3034684ddb6SLionel Sambuc } 3044684ddb6SLionel Sambuc return *this; 3054684ddb6SLionel Sambuc } 3064684ddb6SLionel Sambuc 3074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) 3084684ddb6SLionel Sambuc { 3094684ddb6SLionel Sambuc __deque_iterator __tmp = *this; 3104684ddb6SLionel Sambuc ++(*this); 3114684ddb6SLionel Sambuc return __tmp; 3124684ddb6SLionel Sambuc } 3134684ddb6SLionel Sambuc 3144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() 3154684ddb6SLionel Sambuc { 3164684ddb6SLionel Sambuc if (__ptr_ == *__m_iter_) 3174684ddb6SLionel Sambuc { 3184684ddb6SLionel Sambuc --__m_iter_; 3194684ddb6SLionel Sambuc __ptr_ = *__m_iter_ + __block_size; 3204684ddb6SLionel Sambuc } 3214684ddb6SLionel Sambuc --__ptr_; 3224684ddb6SLionel Sambuc return *this; 3234684ddb6SLionel Sambuc } 3244684ddb6SLionel Sambuc 3254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) 3264684ddb6SLionel Sambuc { 3274684ddb6SLionel Sambuc __deque_iterator __tmp = *this; 3284684ddb6SLionel Sambuc --(*this); 3294684ddb6SLionel Sambuc return __tmp; 3304684ddb6SLionel Sambuc } 3314684ddb6SLionel Sambuc 3324684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) 3334684ddb6SLionel Sambuc { 3344684ddb6SLionel Sambuc if (__n != 0) 3354684ddb6SLionel Sambuc { 3364684ddb6SLionel Sambuc __n += __ptr_ - *__m_iter_; 3374684ddb6SLionel Sambuc if (__n > 0) 3384684ddb6SLionel Sambuc { 3394684ddb6SLionel Sambuc __m_iter_ += __n / __block_size; 3404684ddb6SLionel Sambuc __ptr_ = *__m_iter_ + __n % __block_size; 3414684ddb6SLionel Sambuc } 3424684ddb6SLionel Sambuc else // (__n < 0) 3434684ddb6SLionel Sambuc { 3444684ddb6SLionel Sambuc difference_type __z = __block_size - 1 - __n; 3454684ddb6SLionel Sambuc __m_iter_ -= __z / __block_size; 3464684ddb6SLionel Sambuc __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); 3474684ddb6SLionel Sambuc } 3484684ddb6SLionel Sambuc } 3494684ddb6SLionel Sambuc return *this; 3504684ddb6SLionel Sambuc } 3514684ddb6SLionel Sambuc 3524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) 3534684ddb6SLionel Sambuc { 3544684ddb6SLionel Sambuc return *this += -__n; 3554684ddb6SLionel Sambuc } 3564684ddb6SLionel Sambuc 3574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const 3584684ddb6SLionel Sambuc { 3594684ddb6SLionel Sambuc __deque_iterator __t(*this); 3604684ddb6SLionel Sambuc __t += __n; 3614684ddb6SLionel Sambuc return __t; 3624684ddb6SLionel Sambuc } 3634684ddb6SLionel Sambuc 3644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const 3654684ddb6SLionel Sambuc { 3664684ddb6SLionel Sambuc __deque_iterator __t(*this); 3674684ddb6SLionel Sambuc __t -= __n; 3684684ddb6SLionel Sambuc return __t; 3694684ddb6SLionel Sambuc } 3704684ddb6SLionel Sambuc 3714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3724684ddb6SLionel Sambuc friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) 3734684ddb6SLionel Sambuc {return __it + __n;} 3744684ddb6SLionel Sambuc 3754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3764684ddb6SLionel Sambuc friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) 3774684ddb6SLionel Sambuc { 3784684ddb6SLionel Sambuc if (__x != __y) 3794684ddb6SLionel Sambuc return (__x.__m_iter_ - __y.__m_iter_) * __block_size 3804684ddb6SLionel Sambuc + (__x.__ptr_ - *__x.__m_iter_) 3814684ddb6SLionel Sambuc - (__y.__ptr_ - *__y.__m_iter_); 3824684ddb6SLionel Sambuc return 0; 3834684ddb6SLionel Sambuc } 3844684ddb6SLionel Sambuc 3854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const 3864684ddb6SLionel Sambuc {return *(*this + __n);} 3874684ddb6SLionel Sambuc 3884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 3894684ddb6SLionel Sambuc bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) 3904684ddb6SLionel Sambuc {return __x.__ptr_ == __y.__ptr_;} 3914684ddb6SLionel Sambuc 3924684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 3934684ddb6SLionel Sambuc bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) 3944684ddb6SLionel Sambuc {return !(__x == __y);} 3954684ddb6SLionel Sambuc 3964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 3974684ddb6SLionel Sambuc bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) 3984684ddb6SLionel Sambuc {return __x.__m_iter_ < __y.__m_iter_ || 3994684ddb6SLionel Sambuc (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} 4004684ddb6SLionel Sambuc 4014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 4024684ddb6SLionel Sambuc bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) 4034684ddb6SLionel Sambuc {return __y < __x;} 4044684ddb6SLionel Sambuc 4054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 4064684ddb6SLionel Sambuc bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) 4074684ddb6SLionel Sambuc {return !(__y < __x);} 4084684ddb6SLionel Sambuc 4094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY friend 4104684ddb6SLionel Sambuc bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) 4114684ddb6SLionel Sambuc {return !(__x < __y);} 4124684ddb6SLionel Sambuc 4134684ddb6SLionel Sambucprivate: 4144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT 4154684ddb6SLionel Sambuc : __m_iter_(__m), __ptr_(__p) {} 4164684ddb6SLionel Sambuc 4174684ddb6SLionel Sambuc template <class _Tp, class _Ap> friend class __deque_base; 4184684ddb6SLionel Sambuc template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque; 4194684ddb6SLionel Sambuc template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> 4204684ddb6SLionel Sambuc friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; 4214684ddb6SLionel Sambuc 4224684ddb6SLionel Sambuc template <class _RAIter, 4234684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4244684ddb6SLionel Sambuc friend 4254684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4264684ddb6SLionel Sambuc copy(_RAIter __f, 4274684ddb6SLionel Sambuc _RAIter __l, 4284684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 4294684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); 4304684ddb6SLionel Sambuc 4314684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4324684ddb6SLionel Sambuc class _OutputIterator> 4334684ddb6SLionel Sambuc friend 4344684ddb6SLionel Sambuc _OutputIterator 4354684ddb6SLionel Sambuc copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4364684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4374684ddb6SLionel Sambuc _OutputIterator __r); 4384684ddb6SLionel Sambuc 4394684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4404684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4414684ddb6SLionel Sambuc friend 4424684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4434684ddb6SLionel Sambuc copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4444684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4454684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 4464684ddb6SLionel Sambuc 4474684ddb6SLionel Sambuc template <class _RAIter, 4484684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4494684ddb6SLionel Sambuc friend 4504684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4514684ddb6SLionel Sambuc copy_backward(_RAIter __f, 4524684ddb6SLionel Sambuc _RAIter __l, 4534684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 4544684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); 4554684ddb6SLionel Sambuc 4564684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4574684ddb6SLionel Sambuc class _OutputIterator> 4584684ddb6SLionel Sambuc friend 4594684ddb6SLionel Sambuc _OutputIterator 4604684ddb6SLionel Sambuc copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4614684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4624684ddb6SLionel Sambuc _OutputIterator __r); 4634684ddb6SLionel Sambuc 4644684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4654684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4664684ddb6SLionel Sambuc friend 4674684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4684684ddb6SLionel Sambuc copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4694684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4704684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 4714684ddb6SLionel Sambuc 4724684ddb6SLionel Sambuc template <class _RAIter, 4734684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4744684ddb6SLionel Sambuc friend 4754684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4764684ddb6SLionel Sambuc move(_RAIter __f, 4774684ddb6SLionel Sambuc _RAIter __l, 4784684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 4794684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); 4804684ddb6SLionel Sambuc 4814684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4824684ddb6SLionel Sambuc class _OutputIterator> 4834684ddb6SLionel Sambuc friend 4844684ddb6SLionel Sambuc _OutputIterator 4854684ddb6SLionel Sambuc move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4864684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4874684ddb6SLionel Sambuc _OutputIterator __r); 4884684ddb6SLionel Sambuc 4894684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 4904684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4914684ddb6SLionel Sambuc friend 4924684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 4934684ddb6SLionel Sambuc move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 4944684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 4954684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 4964684ddb6SLionel Sambuc 4974684ddb6SLionel Sambuc template <class _RAIter, 4984684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 4994684ddb6SLionel Sambuc friend 5004684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5014684ddb6SLionel Sambuc move_backward(_RAIter __f, 5024684ddb6SLionel Sambuc _RAIter __l, 5034684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 5044684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); 5054684ddb6SLionel Sambuc 5064684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5074684ddb6SLionel Sambuc class _OutputIterator> 5084684ddb6SLionel Sambuc friend 5094684ddb6SLionel Sambuc _OutputIterator 5104684ddb6SLionel Sambuc move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5114684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5124684ddb6SLionel Sambuc _OutputIterator __r); 5134684ddb6SLionel Sambuc 5144684ddb6SLionel Sambuc template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5154684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5164684ddb6SLionel Sambuc friend 5174684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5184684ddb6SLionel Sambuc move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5194684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5204684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); 5214684ddb6SLionel Sambuc}; 5224684ddb6SLionel Sambuc 5234684ddb6SLionel Sambuc// copy 5244684ddb6SLionel Sambuc 5254684ddb6SLionel Sambuctemplate <class _RAIter, 5264684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5274684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5284684ddb6SLionel Sambuccopy(_RAIter __f, 5294684ddb6SLionel Sambuc _RAIter __l, 5304684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 5314684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) 5324684ddb6SLionel Sambuc{ 5334684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 5344684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 5354684ddb6SLionel Sambuc while (__f != __l) 5364684ddb6SLionel Sambuc { 5374684ddb6SLionel Sambuc pointer __rb = __r.__ptr_; 5384684ddb6SLionel Sambuc pointer __re = *__r.__m_iter_ + _B2; 5394684ddb6SLionel Sambuc difference_type __bs = __re - __rb; 5404684ddb6SLionel Sambuc difference_type __n = __l - __f; 5414684ddb6SLionel Sambuc _RAIter __m = __l; 5424684ddb6SLionel Sambuc if (__n > __bs) 5434684ddb6SLionel Sambuc { 5444684ddb6SLionel Sambuc __n = __bs; 5454684ddb6SLionel Sambuc __m = __f + __n; 5464684ddb6SLionel Sambuc } 5474684ddb6SLionel Sambuc _VSTD::copy(__f, __m, __rb); 5484684ddb6SLionel Sambuc __f = __m; 5494684ddb6SLionel Sambuc __r += __n; 5504684ddb6SLionel Sambuc } 5514684ddb6SLionel Sambuc return __r; 5524684ddb6SLionel Sambuc} 5534684ddb6SLionel Sambuc 5544684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5554684ddb6SLionel Sambuc class _OutputIterator> 5564684ddb6SLionel Sambuc_OutputIterator 5574684ddb6SLionel Sambuccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5584684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5594684ddb6SLionel Sambuc _OutputIterator __r) 5604684ddb6SLionel Sambuc{ 5614684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 5624684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 5634684ddb6SLionel Sambuc difference_type __n = __l - __f; 5644684ddb6SLionel Sambuc while (__n > 0) 5654684ddb6SLionel Sambuc { 5664684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 5674684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + _B1; 5684684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 5694684ddb6SLionel Sambuc if (__bs > __n) 5704684ddb6SLionel Sambuc { 5714684ddb6SLionel Sambuc __bs = __n; 5724684ddb6SLionel Sambuc __fe = __fb + __bs; 5734684ddb6SLionel Sambuc } 5744684ddb6SLionel Sambuc __r = _VSTD::copy(__fb, __fe, __r); 5754684ddb6SLionel Sambuc __n -= __bs; 5764684ddb6SLionel Sambuc __f += __bs; 5774684ddb6SLionel Sambuc } 5784684ddb6SLionel Sambuc return __r; 5794684ddb6SLionel Sambuc} 5804684ddb6SLionel Sambuc 5814684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 5824684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 5834684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 5844684ddb6SLionel Sambuccopy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 5854684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 5864684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 5874684ddb6SLionel Sambuc{ 5884684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 5894684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 5904684ddb6SLionel Sambuc difference_type __n = __l - __f; 5914684ddb6SLionel Sambuc while (__n > 0) 5924684ddb6SLionel Sambuc { 5934684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 5944684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + _B1; 5954684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 5964684ddb6SLionel Sambuc if (__bs > __n) 5974684ddb6SLionel Sambuc { 5984684ddb6SLionel Sambuc __bs = __n; 5994684ddb6SLionel Sambuc __fe = __fb + __bs; 6004684ddb6SLionel Sambuc } 6014684ddb6SLionel Sambuc __r = _VSTD::copy(__fb, __fe, __r); 6024684ddb6SLionel Sambuc __n -= __bs; 6034684ddb6SLionel Sambuc __f += __bs; 6044684ddb6SLionel Sambuc } 6054684ddb6SLionel Sambuc return __r; 6064684ddb6SLionel Sambuc} 6074684ddb6SLionel Sambuc 6084684ddb6SLionel Sambuc// copy_backward 6094684ddb6SLionel Sambuc 6104684ddb6SLionel Sambuctemplate <class _RAIter, 6114684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 6124684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 6134684ddb6SLionel Sambuccopy_backward(_RAIter __f, 6144684ddb6SLionel Sambuc _RAIter __l, 6154684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 6164684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) 6174684ddb6SLionel Sambuc{ 6184684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 6194684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 6204684ddb6SLionel Sambuc while (__f != __l) 6214684ddb6SLionel Sambuc { 6224684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); 6234684ddb6SLionel Sambuc pointer __rb = *__rp.__m_iter_; 6244684ddb6SLionel Sambuc pointer __re = __rp.__ptr_ + 1; 6254684ddb6SLionel Sambuc difference_type __bs = __re - __rb; 6264684ddb6SLionel Sambuc difference_type __n = __l - __f; 6274684ddb6SLionel Sambuc _RAIter __m = __f; 6284684ddb6SLionel Sambuc if (__n > __bs) 6294684ddb6SLionel Sambuc { 6304684ddb6SLionel Sambuc __n = __bs; 6314684ddb6SLionel Sambuc __m = __l - __n; 6324684ddb6SLionel Sambuc } 6334684ddb6SLionel Sambuc _VSTD::copy_backward(__m, __l, __re); 6344684ddb6SLionel Sambuc __l = __m; 6354684ddb6SLionel Sambuc __r -= __n; 6364684ddb6SLionel Sambuc } 6374684ddb6SLionel Sambuc return __r; 6384684ddb6SLionel Sambuc} 6394684ddb6SLionel Sambuc 6404684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 6414684ddb6SLionel Sambuc class _OutputIterator> 6424684ddb6SLionel Sambuc_OutputIterator 6434684ddb6SLionel Sambuccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 6444684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 6454684ddb6SLionel Sambuc _OutputIterator __r) 6464684ddb6SLionel Sambuc{ 6474684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 6484684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 6494684ddb6SLionel Sambuc difference_type __n = __l - __f; 6504684ddb6SLionel Sambuc while (__n > 0) 6514684ddb6SLionel Sambuc { 6524684ddb6SLionel Sambuc --__l; 6534684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 6544684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 6554684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 6564684ddb6SLionel Sambuc if (__bs > __n) 6574684ddb6SLionel Sambuc { 6584684ddb6SLionel Sambuc __bs = __n; 6594684ddb6SLionel Sambuc __lb = __le - __bs; 6604684ddb6SLionel Sambuc } 6614684ddb6SLionel Sambuc __r = _VSTD::copy_backward(__lb, __le, __r); 6624684ddb6SLionel Sambuc __n -= __bs; 6634684ddb6SLionel Sambuc __l -= __bs - 1; 6644684ddb6SLionel Sambuc } 6654684ddb6SLionel Sambuc return __r; 6664684ddb6SLionel Sambuc} 6674684ddb6SLionel Sambuc 6684684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 6694684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 6704684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 6714684ddb6SLionel Sambuccopy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 6724684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 6734684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 6744684ddb6SLionel Sambuc{ 6754684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 6764684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 6774684ddb6SLionel Sambuc difference_type __n = __l - __f; 6784684ddb6SLionel Sambuc while (__n > 0) 6794684ddb6SLionel Sambuc { 6804684ddb6SLionel Sambuc --__l; 6814684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 6824684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 6834684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 6844684ddb6SLionel Sambuc if (__bs > __n) 6854684ddb6SLionel Sambuc { 6864684ddb6SLionel Sambuc __bs = __n; 6874684ddb6SLionel Sambuc __lb = __le - __bs; 6884684ddb6SLionel Sambuc } 6894684ddb6SLionel Sambuc __r = _VSTD::copy_backward(__lb, __le, __r); 6904684ddb6SLionel Sambuc __n -= __bs; 6914684ddb6SLionel Sambuc __l -= __bs - 1; 6924684ddb6SLionel Sambuc } 6934684ddb6SLionel Sambuc return __r; 6944684ddb6SLionel Sambuc} 6954684ddb6SLionel Sambuc 6964684ddb6SLionel Sambuc// move 6974684ddb6SLionel Sambuc 6984684ddb6SLionel Sambuctemplate <class _RAIter, 6994684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7004684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7014684ddb6SLionel Sambucmove(_RAIter __f, 7024684ddb6SLionel Sambuc _RAIter __l, 7034684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 7044684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) 7054684ddb6SLionel Sambuc{ 7064684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 7074684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 7084684ddb6SLionel Sambuc while (__f != __l) 7094684ddb6SLionel Sambuc { 7104684ddb6SLionel Sambuc pointer __rb = __r.__ptr_; 7114684ddb6SLionel Sambuc pointer __re = *__r.__m_iter_ + _B2; 7124684ddb6SLionel Sambuc difference_type __bs = __re - __rb; 7134684ddb6SLionel Sambuc difference_type __n = __l - __f; 7144684ddb6SLionel Sambuc _RAIter __m = __l; 7154684ddb6SLionel Sambuc if (__n > __bs) 7164684ddb6SLionel Sambuc { 7174684ddb6SLionel Sambuc __n = __bs; 7184684ddb6SLionel Sambuc __m = __f + __n; 7194684ddb6SLionel Sambuc } 7204684ddb6SLionel Sambuc _VSTD::move(__f, __m, __rb); 7214684ddb6SLionel Sambuc __f = __m; 7224684ddb6SLionel Sambuc __r += __n; 7234684ddb6SLionel Sambuc } 7244684ddb6SLionel Sambuc return __r; 7254684ddb6SLionel Sambuc} 7264684ddb6SLionel Sambuc 7274684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 7284684ddb6SLionel Sambuc class _OutputIterator> 7294684ddb6SLionel Sambuc_OutputIterator 7304684ddb6SLionel Sambucmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 7314684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 7324684ddb6SLionel Sambuc _OutputIterator __r) 7334684ddb6SLionel Sambuc{ 7344684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 7354684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 7364684ddb6SLionel Sambuc difference_type __n = __l - __f; 7374684ddb6SLionel Sambuc while (__n > 0) 7384684ddb6SLionel Sambuc { 7394684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 7404684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + _B1; 7414684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 7424684ddb6SLionel Sambuc if (__bs > __n) 7434684ddb6SLionel Sambuc { 7444684ddb6SLionel Sambuc __bs = __n; 7454684ddb6SLionel Sambuc __fe = __fb + __bs; 7464684ddb6SLionel Sambuc } 7474684ddb6SLionel Sambuc __r = _VSTD::move(__fb, __fe, __r); 7484684ddb6SLionel Sambuc __n -= __bs; 7494684ddb6SLionel Sambuc __f += __bs; 7504684ddb6SLionel Sambuc } 7514684ddb6SLionel Sambuc return __r; 7524684ddb6SLionel Sambuc} 7534684ddb6SLionel Sambuc 7544684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 7554684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7564684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7574684ddb6SLionel Sambucmove(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 7584684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 7594684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 7604684ddb6SLionel Sambuc{ 7614684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 7624684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 7634684ddb6SLionel Sambuc difference_type __n = __l - __f; 7644684ddb6SLionel Sambuc while (__n > 0) 7654684ddb6SLionel Sambuc { 7664684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 7674684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + _B1; 7684684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 7694684ddb6SLionel Sambuc if (__bs > __n) 7704684ddb6SLionel Sambuc { 7714684ddb6SLionel Sambuc __bs = __n; 7724684ddb6SLionel Sambuc __fe = __fb + __bs; 7734684ddb6SLionel Sambuc } 7744684ddb6SLionel Sambuc __r = _VSTD::move(__fb, __fe, __r); 7754684ddb6SLionel Sambuc __n -= __bs; 7764684ddb6SLionel Sambuc __f += __bs; 7774684ddb6SLionel Sambuc } 7784684ddb6SLionel Sambuc return __r; 7794684ddb6SLionel Sambuc} 7804684ddb6SLionel Sambuc 7814684ddb6SLionel Sambuc// move_backward 7824684ddb6SLionel Sambuc 7834684ddb6SLionel Sambuctemplate <class _RAIter, 7844684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 7854684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 7864684ddb6SLionel Sambucmove_backward(_RAIter __f, 7874684ddb6SLionel Sambuc _RAIter __l, 7884684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, 7894684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) 7904684ddb6SLionel Sambuc{ 7914684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; 7924684ddb6SLionel Sambuc typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; 7934684ddb6SLionel Sambuc while (__f != __l) 7944684ddb6SLionel Sambuc { 7954684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); 7964684ddb6SLionel Sambuc pointer __rb = *__rp.__m_iter_; 7974684ddb6SLionel Sambuc pointer __re = __rp.__ptr_ + 1; 7984684ddb6SLionel Sambuc difference_type __bs = __re - __rb; 7994684ddb6SLionel Sambuc difference_type __n = __l - __f; 8004684ddb6SLionel Sambuc _RAIter __m = __f; 8014684ddb6SLionel Sambuc if (__n > __bs) 8024684ddb6SLionel Sambuc { 8034684ddb6SLionel Sambuc __n = __bs; 8044684ddb6SLionel Sambuc __m = __l - __n; 8054684ddb6SLionel Sambuc } 8064684ddb6SLionel Sambuc _VSTD::move_backward(__m, __l, __re); 8074684ddb6SLionel Sambuc __l = __m; 8084684ddb6SLionel Sambuc __r -= __n; 8094684ddb6SLionel Sambuc } 8104684ddb6SLionel Sambuc return __r; 8114684ddb6SLionel Sambuc} 8124684ddb6SLionel Sambuc 8134684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 8144684ddb6SLionel Sambuc class _OutputIterator> 8154684ddb6SLionel Sambuc_OutputIterator 8164684ddb6SLionel Sambucmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 8174684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 8184684ddb6SLionel Sambuc _OutputIterator __r) 8194684ddb6SLionel Sambuc{ 8204684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 8214684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 8224684ddb6SLionel Sambuc difference_type __n = __l - __f; 8234684ddb6SLionel Sambuc while (__n > 0) 8244684ddb6SLionel Sambuc { 8254684ddb6SLionel Sambuc --__l; 8264684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 8274684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 8284684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 8294684ddb6SLionel Sambuc if (__bs > __n) 8304684ddb6SLionel Sambuc { 8314684ddb6SLionel Sambuc __bs = __n; 8324684ddb6SLionel Sambuc __lb = __le - __bs; 8334684ddb6SLionel Sambuc } 8344684ddb6SLionel Sambuc __r = _VSTD::move_backward(__lb, __le, __r); 8354684ddb6SLionel Sambuc __n -= __bs; 8364684ddb6SLionel Sambuc __l -= __bs - 1; 8374684ddb6SLionel Sambuc } 8384684ddb6SLionel Sambuc return __r; 8394684ddb6SLionel Sambuc} 8404684ddb6SLionel Sambuc 8414684ddb6SLionel Sambuctemplate <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, 8424684ddb6SLionel Sambuc class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> 8434684ddb6SLionel Sambuc__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> 8444684ddb6SLionel Sambucmove_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, 8454684ddb6SLionel Sambuc __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, 8464684ddb6SLionel Sambuc __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) 8474684ddb6SLionel Sambuc{ 8484684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; 8494684ddb6SLionel Sambuc typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; 8504684ddb6SLionel Sambuc difference_type __n = __l - __f; 8514684ddb6SLionel Sambuc while (__n > 0) 8524684ddb6SLionel Sambuc { 8534684ddb6SLionel Sambuc --__l; 8544684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 8554684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 8564684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 8574684ddb6SLionel Sambuc if (__bs > __n) 8584684ddb6SLionel Sambuc { 8594684ddb6SLionel Sambuc __bs = __n; 8604684ddb6SLionel Sambuc __lb = __le - __bs; 8614684ddb6SLionel Sambuc } 8624684ddb6SLionel Sambuc __r = _VSTD::move_backward(__lb, __le, __r); 8634684ddb6SLionel Sambuc __n -= __bs; 8644684ddb6SLionel Sambuc __l -= __bs - 1; 8654684ddb6SLionel Sambuc } 8664684ddb6SLionel Sambuc return __r; 8674684ddb6SLionel Sambuc} 8684684ddb6SLionel Sambuc 8694684ddb6SLionel Sambuctemplate <bool> 8704684ddb6SLionel Sambucclass __deque_base_common 8714684ddb6SLionel Sambuc{ 8724684ddb6SLionel Sambucprotected: 8734684ddb6SLionel Sambuc void __throw_length_error() const; 8744684ddb6SLionel Sambuc void __throw_out_of_range() const; 8754684ddb6SLionel Sambuc}; 8764684ddb6SLionel Sambuc 8774684ddb6SLionel Sambuctemplate <bool __b> 8784684ddb6SLionel Sambucvoid 8794684ddb6SLionel Sambuc__deque_base_common<__b>::__throw_length_error() const 8804684ddb6SLionel Sambuc{ 8814684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 8824684ddb6SLionel Sambuc throw length_error("deque"); 8834684ddb6SLionel Sambuc#endif 8844684ddb6SLionel Sambuc} 8854684ddb6SLionel Sambuc 8864684ddb6SLionel Sambuctemplate <bool __b> 8874684ddb6SLionel Sambucvoid 8884684ddb6SLionel Sambuc__deque_base_common<__b>::__throw_out_of_range() const 8894684ddb6SLionel Sambuc{ 8904684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 8914684ddb6SLionel Sambuc throw out_of_range("deque"); 8924684ddb6SLionel Sambuc#endif 8934684ddb6SLionel Sambuc} 8944684ddb6SLionel Sambuc 8954684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 8964684ddb6SLionel Sambucclass __deque_base 8974684ddb6SLionel Sambuc : protected __deque_base_common<true> 8984684ddb6SLionel Sambuc{ 8994684ddb6SLionel Sambuc __deque_base(const __deque_base& __c); 9004684ddb6SLionel Sambuc __deque_base& operator=(const __deque_base& __c); 9014684ddb6SLionel Sambucprotected: 9024684ddb6SLionel Sambuc typedef _Tp value_type; 9034684ddb6SLionel Sambuc typedef _Allocator allocator_type; 9044684ddb6SLionel Sambuc typedef allocator_traits<allocator_type> __alloc_traits; 9054684ddb6SLionel Sambuc typedef value_type& reference; 9064684ddb6SLionel Sambuc typedef const value_type& const_reference; 9074684ddb6SLionel Sambuc typedef typename __alloc_traits::size_type size_type; 9084684ddb6SLionel Sambuc typedef typename __alloc_traits::difference_type difference_type; 9094684ddb6SLionel Sambuc typedef typename __alloc_traits::pointer pointer; 9104684ddb6SLionel Sambuc typedef typename __alloc_traits::const_pointer const_pointer; 9114684ddb6SLionel Sambuc 9124684ddb6SLionel Sambuc static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; 9134684ddb6SLionel Sambuc 914*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; 9154684ddb6SLionel Sambuc typedef allocator_traits<__pointer_allocator> __map_traits; 9164684ddb6SLionel Sambuc typedef typename __map_traits::pointer __map_pointer; 917*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; 9184684ddb6SLionel Sambuc typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; 9194684ddb6SLionel Sambuc typedef __split_buffer<pointer, __pointer_allocator> __map; 9204684ddb6SLionel Sambuc 9214684ddb6SLionel Sambuc typedef __deque_iterator<value_type, pointer, reference, __map_pointer, 9224684ddb6SLionel Sambuc difference_type, __block_size> iterator; 9234684ddb6SLionel Sambuc typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, 9244684ddb6SLionel Sambuc difference_type, __block_size> const_iterator; 9254684ddb6SLionel Sambuc 9264684ddb6SLionel Sambuc __map __map_; 9274684ddb6SLionel Sambuc size_type __start_; 9284684ddb6SLionel Sambuc __compressed_pair<size_type, allocator_type> __size_; 9294684ddb6SLionel Sambuc 9304684ddb6SLionel Sambuc iterator begin() _NOEXCEPT; 9314684ddb6SLionel Sambuc const_iterator begin() const _NOEXCEPT; 9324684ddb6SLionel Sambuc iterator end() _NOEXCEPT; 9334684ddb6SLionel Sambuc const_iterator end() const _NOEXCEPT; 9344684ddb6SLionel Sambuc 9354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} 9364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9374684ddb6SLionel Sambuc const size_type& size() const _NOEXCEPT {return __size_.first();} 9384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} 9394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9404684ddb6SLionel Sambuc const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} 9414684ddb6SLionel Sambuc 9424684ddb6SLionel Sambuc __deque_base() 9434684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 9444684ddb6SLionel Sambuc explicit __deque_base(const allocator_type& __a); 9454684ddb6SLionel Sambucpublic: 9464684ddb6SLionel Sambuc ~__deque_base(); 9474684ddb6SLionel Sambuc 9484684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 9494684ddb6SLionel Sambuc 9504684ddb6SLionel Sambuc __deque_base(__deque_base&& __c) 9514684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 9524684ddb6SLionel Sambuc __deque_base(__deque_base&& __c, const allocator_type& __a); 9534684ddb6SLionel Sambuc 9544684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 9554684ddb6SLionel Sambuc void swap(__deque_base& __c) 956*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 957*0a6a1f1dSLionel Sambuc _NOEXCEPT; 958*0a6a1f1dSLionel Sambuc#else 9594684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 9604684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value); 961*0a6a1f1dSLionel Sambuc#endif 9624684ddb6SLionel Sambucprotected: 9634684ddb6SLionel Sambuc void clear() _NOEXCEPT; 9644684ddb6SLionel Sambuc 9654684ddb6SLionel Sambuc bool __invariants() const; 9664684ddb6SLionel Sambuc 9674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9684684ddb6SLionel Sambuc void __move_assign(__deque_base& __c) 9694684ddb6SLionel Sambuc _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 9704684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value) 9714684ddb6SLionel Sambuc { 9724684ddb6SLionel Sambuc __map_ = _VSTD::move(__c.__map_); 9734684ddb6SLionel Sambuc __start_ = __c.__start_; 9744684ddb6SLionel Sambuc size() = __c.size(); 9754684ddb6SLionel Sambuc __move_assign_alloc(__c); 9764684ddb6SLionel Sambuc __c.__start_ = __c.size() = 0; 9774684ddb6SLionel Sambuc } 9784684ddb6SLionel Sambuc 9794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9804684ddb6SLionel Sambuc void __move_assign_alloc(__deque_base& __c) 9814684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || 9824684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value) 9834684ddb6SLionel Sambuc {__move_assign_alloc(__c, integral_constant<bool, 9844684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_move_assignment::value>());} 9854684ddb6SLionel Sambuc 9864684ddb6SLionel Sambucprivate: 9874684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9884684ddb6SLionel Sambuc void __move_assign_alloc(__deque_base& __c, true_type) 9894684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 9904684ddb6SLionel Sambuc { 9914684ddb6SLionel Sambuc __alloc() = _VSTD::move(__c.__alloc()); 9924684ddb6SLionel Sambuc } 9934684ddb6SLionel Sambuc 9944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 9954684ddb6SLionel Sambuc void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT 9964684ddb6SLionel Sambuc {} 9974684ddb6SLionel Sambuc}; 9984684ddb6SLionel Sambuc 9994684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10004684ddb6SLionel Sambucbool 10014684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::__invariants() const 10024684ddb6SLionel Sambuc{ 10034684ddb6SLionel Sambuc if (!__map_.__invariants()) 10044684ddb6SLionel Sambuc return false; 10054684ddb6SLionel Sambuc if (__map_.size() >= size_type(-1) / __block_size) 10064684ddb6SLionel Sambuc return false; 10074684ddb6SLionel Sambuc for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); 10084684ddb6SLionel Sambuc __i != __e; ++__i) 10094684ddb6SLionel Sambuc if (*__i == nullptr) 10104684ddb6SLionel Sambuc return false; 10114684ddb6SLionel Sambuc if (__map_.size() != 0) 10124684ddb6SLionel Sambuc { 10134684ddb6SLionel Sambuc if (size() >= __map_.size() * __block_size) 10144684ddb6SLionel Sambuc return false; 10154684ddb6SLionel Sambuc if (__start_ >= __map_.size() * __block_size - size()) 10164684ddb6SLionel Sambuc return false; 10174684ddb6SLionel Sambuc } 10184684ddb6SLionel Sambuc else 10194684ddb6SLionel Sambuc { 10204684ddb6SLionel Sambuc if (size() != 0) 10214684ddb6SLionel Sambuc return false; 10224684ddb6SLionel Sambuc if (__start_ != 0) 10234684ddb6SLionel Sambuc return false; 10244684ddb6SLionel Sambuc } 10254684ddb6SLionel Sambuc return true; 10264684ddb6SLionel Sambuc} 10274684ddb6SLionel Sambuc 10284684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10294684ddb6SLionel Sambuctypename __deque_base<_Tp, _Allocator>::iterator 10304684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT 10314684ddb6SLionel Sambuc{ 10324684ddb6SLionel Sambuc __map_pointer __mp = __map_.begin() + __start_ / __block_size; 10334684ddb6SLionel Sambuc return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); 10344684ddb6SLionel Sambuc} 10354684ddb6SLionel Sambuc 10364684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10374684ddb6SLionel Sambuctypename __deque_base<_Tp, _Allocator>::const_iterator 10384684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT 10394684ddb6SLionel Sambuc{ 10404684ddb6SLionel Sambuc __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); 10414684ddb6SLionel Sambuc return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); 10424684ddb6SLionel Sambuc} 10434684ddb6SLionel Sambuc 10444684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10454684ddb6SLionel Sambuctypename __deque_base<_Tp, _Allocator>::iterator 10464684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::end() _NOEXCEPT 10474684ddb6SLionel Sambuc{ 10484684ddb6SLionel Sambuc size_type __p = size() + __start_; 10494684ddb6SLionel Sambuc __map_pointer __mp = __map_.begin() + __p / __block_size; 10504684ddb6SLionel Sambuc return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); 10514684ddb6SLionel Sambuc} 10524684ddb6SLionel Sambuc 10534684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10544684ddb6SLionel Sambuctypename __deque_base<_Tp, _Allocator>::const_iterator 10554684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT 10564684ddb6SLionel Sambuc{ 10574684ddb6SLionel Sambuc size_type __p = size() + __start_; 10584684ddb6SLionel Sambuc __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); 10594684ddb6SLionel Sambuc return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); 10604684ddb6SLionel Sambuc} 10614684ddb6SLionel Sambuc 10624684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10634684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10644684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::__deque_base() 10654684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 10664684ddb6SLionel Sambuc : __start_(0), __size_(0) {} 10674684ddb6SLionel Sambuc 10684684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10694684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10704684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) 10714684ddb6SLionel Sambuc : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} 10724684ddb6SLionel Sambuc 10734684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10744684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::~__deque_base() 10754684ddb6SLionel Sambuc{ 10764684ddb6SLionel Sambuc clear(); 10774684ddb6SLionel Sambuc typename __map::iterator __i = __map_.begin(); 10784684ddb6SLionel Sambuc typename __map::iterator __e = __map_.end(); 10794684ddb6SLionel Sambuc for (; __i != __e; ++__i) 10804684ddb6SLionel Sambuc __alloc_traits::deallocate(__alloc(), *__i, __block_size); 10814684ddb6SLionel Sambuc} 10824684ddb6SLionel Sambuc 10834684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10844684ddb6SLionel Sambuc 10854684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10864684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) 10874684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 10884684ddb6SLionel Sambuc : __map_(_VSTD::move(__c.__map_)), 10894684ddb6SLionel Sambuc __start_(_VSTD::move(__c.__start_)), 10904684ddb6SLionel Sambuc __size_(_VSTD::move(__c.__size_)) 10914684ddb6SLionel Sambuc{ 10924684ddb6SLionel Sambuc __c.__start_ = 0; 10934684ddb6SLionel Sambuc __c.size() = 0; 10944684ddb6SLionel Sambuc} 10954684ddb6SLionel Sambuc 10964684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10974684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) 10984684ddb6SLionel Sambuc : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), 10994684ddb6SLionel Sambuc __start_(_VSTD::move(__c.__start_)), 11004684ddb6SLionel Sambuc __size_(_VSTD::move(__c.size()), __a) 11014684ddb6SLionel Sambuc{ 11024684ddb6SLionel Sambuc if (__a == __c.__alloc()) 11034684ddb6SLionel Sambuc { 11044684ddb6SLionel Sambuc __c.__start_ = 0; 11054684ddb6SLionel Sambuc __c.size() = 0; 11064684ddb6SLionel Sambuc } 11074684ddb6SLionel Sambuc else 11084684ddb6SLionel Sambuc { 11094684ddb6SLionel Sambuc __map_.clear(); 11104684ddb6SLionel Sambuc __start_ = 0; 11114684ddb6SLionel Sambuc size() = 0; 11124684ddb6SLionel Sambuc } 11134684ddb6SLionel Sambuc} 11144684ddb6SLionel Sambuc 11154684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 11164684ddb6SLionel Sambuc 11174684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11184684ddb6SLionel Sambucvoid 11194684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::swap(__deque_base& __c) 1120*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 1121*0a6a1f1dSLionel Sambuc _NOEXCEPT 1122*0a6a1f1dSLionel Sambuc#else 11234684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 11244684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value) 1125*0a6a1f1dSLionel Sambuc#endif 11264684ddb6SLionel Sambuc{ 11274684ddb6SLionel Sambuc __map_.swap(__c.__map_); 11284684ddb6SLionel Sambuc _VSTD::swap(__start_, __c.__start_); 11294684ddb6SLionel Sambuc _VSTD::swap(size(), __c.size()); 1130*0a6a1f1dSLionel Sambuc __swap_allocator(__alloc(), __c.__alloc()); 11314684ddb6SLionel Sambuc} 11324684ddb6SLionel Sambuc 11334684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11344684ddb6SLionel Sambucvoid 11354684ddb6SLionel Sambuc__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT 11364684ddb6SLionel Sambuc{ 11374684ddb6SLionel Sambuc allocator_type& __a = __alloc(); 11384684ddb6SLionel Sambuc for (iterator __i = begin(), __e = end(); __i != __e; ++__i) 11394684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 11404684ddb6SLionel Sambuc size() = 0; 11414684ddb6SLionel Sambuc while (__map_.size() > 2) 11424684ddb6SLionel Sambuc { 11434684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __map_.front(), __block_size); 11444684ddb6SLionel Sambuc __map_.pop_front(); 11454684ddb6SLionel Sambuc } 11464684ddb6SLionel Sambuc switch (__map_.size()) 11474684ddb6SLionel Sambuc { 11484684ddb6SLionel Sambuc case 1: 11494684ddb6SLionel Sambuc __start_ = __block_size / 2; 11504684ddb6SLionel Sambuc break; 11514684ddb6SLionel Sambuc case 2: 11524684ddb6SLionel Sambuc __start_ = __block_size; 11534684ddb6SLionel Sambuc break; 11544684ddb6SLionel Sambuc } 11554684ddb6SLionel Sambuc} 11564684ddb6SLionel Sambuc 1157*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Allocator /*= allocator<_Tp>*/> 11584684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY deque 11594684ddb6SLionel Sambuc : private __deque_base<_Tp, _Allocator> 11604684ddb6SLionel Sambuc{ 11614684ddb6SLionel Sambucpublic: 11624684ddb6SLionel Sambuc // types: 11634684ddb6SLionel Sambuc 11644684ddb6SLionel Sambuc typedef _Tp value_type; 11654684ddb6SLionel Sambuc typedef _Allocator allocator_type; 11664684ddb6SLionel Sambuc 11674684ddb6SLionel Sambuc typedef __deque_base<value_type, allocator_type> __base; 11684684ddb6SLionel Sambuc 11694684ddb6SLionel Sambuc typedef typename __base::__alloc_traits __alloc_traits; 11704684ddb6SLionel Sambuc typedef typename __base::reference reference; 11714684ddb6SLionel Sambuc typedef typename __base::const_reference const_reference; 11724684ddb6SLionel Sambuc typedef typename __base::iterator iterator; 11734684ddb6SLionel Sambuc typedef typename __base::const_iterator const_iterator; 11744684ddb6SLionel Sambuc typedef typename __base::size_type size_type; 11754684ddb6SLionel Sambuc typedef typename __base::difference_type difference_type; 11764684ddb6SLionel Sambuc 11774684ddb6SLionel Sambuc typedef typename __base::pointer pointer; 11784684ddb6SLionel Sambuc typedef typename __base::const_pointer const_pointer; 11794684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 11804684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 11814684ddb6SLionel Sambuc 11824684ddb6SLionel Sambuc // construct/copy/destroy: 11834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 11844684ddb6SLionel Sambuc deque() 11854684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 11864684ddb6SLionel Sambuc {} 1187*0a6a1f1dSLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} 11884684ddb6SLionel Sambuc explicit deque(size_type __n); 11894684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 11904684ddb6SLionel Sambuc explicit deque(size_type __n, const _Allocator& __a); 11914684ddb6SLionel Sambuc#endif 11924684ddb6SLionel Sambuc deque(size_type __n, const value_type& __v); 11934684ddb6SLionel Sambuc deque(size_type __n, const value_type& __v, const allocator_type& __a); 11944684ddb6SLionel Sambuc template <class _InputIter> 11954684ddb6SLionel Sambuc deque(_InputIter __f, _InputIter __l, 11964684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); 11974684ddb6SLionel Sambuc template <class _InputIter> 11984684ddb6SLionel Sambuc deque(_InputIter __f, _InputIter __l, const allocator_type& __a, 11994684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); 12004684ddb6SLionel Sambuc deque(const deque& __c); 12014684ddb6SLionel Sambuc deque(const deque& __c, const allocator_type& __a); 12024684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12034684ddb6SLionel Sambuc deque(initializer_list<value_type> __il); 12044684ddb6SLionel Sambuc deque(initializer_list<value_type> __il, const allocator_type& __a); 12054684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12064684ddb6SLionel Sambuc 12074684ddb6SLionel Sambuc deque& operator=(const deque& __c); 12084684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12104684ddb6SLionel Sambuc deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} 12114684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12124684ddb6SLionel Sambuc 12134684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12144684ddb6SLionel Sambuc deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); 12154684ddb6SLionel Sambuc deque(deque&& __c, const allocator_type& __a); 12164684ddb6SLionel Sambuc deque& operator=(deque&& __c) 12174684ddb6SLionel Sambuc _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 12184684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value); 12194684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 12204684ddb6SLionel Sambuc 12214684ddb6SLionel Sambuc template <class _InputIter> 12224684ddb6SLionel Sambuc void assign(_InputIter __f, _InputIter __l, 12234684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value && 12244684ddb6SLionel Sambuc !__is_random_access_iterator<_InputIter>::value>::type* = 0); 12254684ddb6SLionel Sambuc template <class _RAIter> 12264684ddb6SLionel Sambuc void assign(_RAIter __f, _RAIter __l, 12274684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); 12284684ddb6SLionel Sambuc void assign(size_type __n, const value_type& __v); 12294684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12304684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12314684ddb6SLionel Sambuc void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} 12324684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12334684ddb6SLionel Sambuc 12344684ddb6SLionel Sambuc allocator_type get_allocator() const _NOEXCEPT; 12354684ddb6SLionel Sambuc 12364684ddb6SLionel Sambuc // iterators: 12374684ddb6SLionel Sambuc 12384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12394684ddb6SLionel Sambuc iterator begin() _NOEXCEPT {return __base::begin();} 12404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12414684ddb6SLionel Sambuc const_iterator begin() const _NOEXCEPT {return __base::begin();} 12424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12434684ddb6SLionel Sambuc iterator end() _NOEXCEPT {return __base::end();} 12444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12454684ddb6SLionel Sambuc const_iterator end() const _NOEXCEPT {return __base::end();} 12464684ddb6SLionel Sambuc 12474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12484684ddb6SLionel Sambuc reverse_iterator rbegin() _NOEXCEPT 12494684ddb6SLionel Sambuc {return reverse_iterator(__base::end());} 12504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12514684ddb6SLionel Sambuc const_reverse_iterator rbegin() const _NOEXCEPT 12524684ddb6SLionel Sambuc {return const_reverse_iterator(__base::end());} 12534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12544684ddb6SLionel Sambuc reverse_iterator rend() _NOEXCEPT 12554684ddb6SLionel Sambuc {return reverse_iterator(__base::begin());} 12564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12574684ddb6SLionel Sambuc const_reverse_iterator rend() const _NOEXCEPT 12584684ddb6SLionel Sambuc {return const_reverse_iterator(__base::begin());} 12594684ddb6SLionel Sambuc 12604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12614684ddb6SLionel Sambuc const_iterator cbegin() const _NOEXCEPT 12624684ddb6SLionel Sambuc {return __base::begin();} 12634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12644684ddb6SLionel Sambuc const_iterator cend() const _NOEXCEPT 12654684ddb6SLionel Sambuc {return __base::end();} 12664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12674684ddb6SLionel Sambuc const_reverse_iterator crbegin() const _NOEXCEPT 12684684ddb6SLionel Sambuc {return const_reverse_iterator(__base::end());} 12694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12704684ddb6SLionel Sambuc const_reverse_iterator crend() const _NOEXCEPT 12714684ddb6SLionel Sambuc {return const_reverse_iterator(__base::begin());} 12724684ddb6SLionel Sambuc 12734684ddb6SLionel Sambuc // capacity: 12744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12754684ddb6SLionel Sambuc size_type size() const _NOEXCEPT {return __base::size();} 12764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12774684ddb6SLionel Sambuc size_type max_size() const _NOEXCEPT 12784684ddb6SLionel Sambuc {return __alloc_traits::max_size(__base::__alloc());} 12794684ddb6SLionel Sambuc void resize(size_type __n); 12804684ddb6SLionel Sambuc void resize(size_type __n, const value_type& __v); 12814684ddb6SLionel Sambuc void shrink_to_fit() _NOEXCEPT; 12824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12834684ddb6SLionel Sambuc bool empty() const _NOEXCEPT {return __base::size() == 0;} 12844684ddb6SLionel Sambuc 12854684ddb6SLionel Sambuc // element access: 12864684ddb6SLionel Sambuc reference operator[](size_type __i); 12874684ddb6SLionel Sambuc const_reference operator[](size_type __i) const; 12884684ddb6SLionel Sambuc reference at(size_type __i); 12894684ddb6SLionel Sambuc const_reference at(size_type __i) const; 12904684ddb6SLionel Sambuc reference front(); 12914684ddb6SLionel Sambuc const_reference front() const; 12924684ddb6SLionel Sambuc reference back(); 12934684ddb6SLionel Sambuc const_reference back() const; 12944684ddb6SLionel Sambuc 12954684ddb6SLionel Sambuc // 23.2.2.3 modifiers: 12964684ddb6SLionel Sambuc void push_front(const value_type& __v); 12974684ddb6SLionel Sambuc void push_back(const value_type& __v); 12984684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12994684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 13004684ddb6SLionel Sambuc template <class... _Args> void emplace_front(_Args&&... __args); 13014684ddb6SLionel Sambuc template <class... _Args> void emplace_back(_Args&&... __args); 13024684ddb6SLionel Sambuc template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); 13034684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 13044684ddb6SLionel Sambuc void push_front(value_type&& __v); 13054684ddb6SLionel Sambuc void push_back(value_type&& __v); 13064684ddb6SLionel Sambuc iterator insert(const_iterator __p, value_type&& __v); 13074684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13084684ddb6SLionel Sambuc iterator insert(const_iterator __p, const value_type& __v); 13094684ddb6SLionel Sambuc iterator insert(const_iterator __p, size_type __n, const value_type& __v); 13104684ddb6SLionel Sambuc template <class _InputIter> 13114684ddb6SLionel Sambuc iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, 13124684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value 1313*0a6a1f1dSLionel Sambuc &&!__is_forward_iterator<_InputIter>::value>::type* = 0); 1314*0a6a1f1dSLionel Sambuc template <class _ForwardIterator> 1315*0a6a1f1dSLionel Sambuc iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, 1316*0a6a1f1dSLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value 1317*0a6a1f1dSLionel Sambuc &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); 13184684ddb6SLionel Sambuc template <class _BiIter> 13194684ddb6SLionel Sambuc iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, 13204684ddb6SLionel Sambuc typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); 13214684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 13224684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13234684ddb6SLionel Sambuc iterator insert(const_iterator __p, initializer_list<value_type> __il) 13244684ddb6SLionel Sambuc {return insert(__p, __il.begin(), __il.end());} 13254684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 13264684ddb6SLionel Sambuc void pop_front(); 13274684ddb6SLionel Sambuc void pop_back(); 13284684ddb6SLionel Sambuc iterator erase(const_iterator __p); 13294684ddb6SLionel Sambuc iterator erase(const_iterator __f, const_iterator __l); 13304684ddb6SLionel Sambuc 13314684ddb6SLionel Sambuc void swap(deque& __c) 1332*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 1333*0a6a1f1dSLionel Sambuc _NOEXCEPT; 1334*0a6a1f1dSLionel Sambuc#else 13354684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 13364684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value); 1337*0a6a1f1dSLionel Sambuc#endif 13384684ddb6SLionel Sambuc void clear() _NOEXCEPT; 13394684ddb6SLionel Sambuc 13404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13414684ddb6SLionel Sambuc bool __invariants() const {return __base::__invariants();} 13424684ddb6SLionel Sambucprivate: 13434684ddb6SLionel Sambuc typedef typename __base::__map_const_pointer __map_const_pointer; 13444684ddb6SLionel Sambuc 13454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13464684ddb6SLionel Sambuc static size_type __recommend_blocks(size_type __n) 13474684ddb6SLionel Sambuc { 13484684ddb6SLionel Sambuc return __n / __base::__block_size + (__n % __base::__block_size != 0); 13494684ddb6SLionel Sambuc } 13504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13514684ddb6SLionel Sambuc size_type __capacity() const 13524684ddb6SLionel Sambuc { 13534684ddb6SLionel Sambuc return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; 13544684ddb6SLionel Sambuc } 13554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13564684ddb6SLionel Sambuc size_type __front_spare() const 13574684ddb6SLionel Sambuc { 13584684ddb6SLionel Sambuc return __base::__start_; 13594684ddb6SLionel Sambuc } 13604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13614684ddb6SLionel Sambuc size_type __back_spare() const 13624684ddb6SLionel Sambuc { 13634684ddb6SLionel Sambuc return __capacity() - (__base::__start_ + __base::size()); 13644684ddb6SLionel Sambuc } 13654684ddb6SLionel Sambuc 13664684ddb6SLionel Sambuc template <class _InpIter> 13674684ddb6SLionel Sambuc void __append(_InpIter __f, _InpIter __l, 13684684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InpIter>::value && 13694684ddb6SLionel Sambuc !__is_forward_iterator<_InpIter>::value>::type* = 0); 13704684ddb6SLionel Sambuc template <class _ForIter> 13714684ddb6SLionel Sambuc void __append(_ForIter __f, _ForIter __l, 13724684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); 13734684ddb6SLionel Sambuc void __append(size_type __n); 13744684ddb6SLionel Sambuc void __append(size_type __n, const value_type& __v); 13754684ddb6SLionel Sambuc void __erase_to_end(const_iterator __f); 13764684ddb6SLionel Sambuc void __add_front_capacity(); 13774684ddb6SLionel Sambuc void __add_front_capacity(size_type __n); 13784684ddb6SLionel Sambuc void __add_back_capacity(); 13794684ddb6SLionel Sambuc void __add_back_capacity(size_type __n); 13804684ddb6SLionel Sambuc iterator __move_and_check(iterator __f, iterator __l, iterator __r, 13814684ddb6SLionel Sambuc const_pointer& __vt); 13824684ddb6SLionel Sambuc iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, 13834684ddb6SLionel Sambuc const_pointer& __vt); 13844684ddb6SLionel Sambuc void __move_construct_and_check(iterator __f, iterator __l, 13854684ddb6SLionel Sambuc iterator __r, const_pointer& __vt); 13864684ddb6SLionel Sambuc void __move_construct_backward_and_check(iterator __f, iterator __l, 13874684ddb6SLionel Sambuc iterator __r, const_pointer& __vt); 13884684ddb6SLionel Sambuc 13894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13904684ddb6SLionel Sambuc void __copy_assign_alloc(const deque& __c) 13914684ddb6SLionel Sambuc {__copy_assign_alloc(__c, integral_constant<bool, 13924684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_copy_assignment::value>());} 13934684ddb6SLionel Sambuc 13944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13954684ddb6SLionel Sambuc void __copy_assign_alloc(const deque& __c, true_type) 13964684ddb6SLionel Sambuc { 13974684ddb6SLionel Sambuc if (__base::__alloc() != __c.__alloc()) 13984684ddb6SLionel Sambuc { 13994684ddb6SLionel Sambuc clear(); 14004684ddb6SLionel Sambuc shrink_to_fit(); 14014684ddb6SLionel Sambuc } 14024684ddb6SLionel Sambuc __base::__alloc() = __c.__alloc(); 14034684ddb6SLionel Sambuc __base::__map_.__alloc() = __c.__map_.__alloc(); 14044684ddb6SLionel Sambuc } 14054684ddb6SLionel Sambuc 14064684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 14074684ddb6SLionel Sambuc void __copy_assign_alloc(const deque&, false_type) 14084684ddb6SLionel Sambuc {} 14094684ddb6SLionel Sambuc 14104684ddb6SLionel Sambuc void __move_assign(deque& __c, true_type) 14114684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 14124684ddb6SLionel Sambuc void __move_assign(deque& __c, false_type); 14134684ddb6SLionel Sambuc}; 14144684ddb6SLionel Sambuc 14154684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14164684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(size_type __n) 14174684ddb6SLionel Sambuc{ 14184684ddb6SLionel Sambuc if (__n > 0) 14194684ddb6SLionel Sambuc __append(__n); 14204684ddb6SLionel Sambuc} 14214684ddb6SLionel Sambuc 14224684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 14234684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14244684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) 14254684ddb6SLionel Sambuc : __base(__a) 14264684ddb6SLionel Sambuc{ 14274684ddb6SLionel Sambuc if (__n > 0) 14284684ddb6SLionel Sambuc __append(__n); 14294684ddb6SLionel Sambuc} 14304684ddb6SLionel Sambuc#endif 14314684ddb6SLionel Sambuc 14324684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14334684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) 14344684ddb6SLionel Sambuc{ 14354684ddb6SLionel Sambuc if (__n > 0) 14364684ddb6SLionel Sambuc __append(__n, __v); 14374684ddb6SLionel Sambuc} 14384684ddb6SLionel Sambuc 14394684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14404684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) 14414684ddb6SLionel Sambuc : __base(__a) 14424684ddb6SLionel Sambuc{ 14434684ddb6SLionel Sambuc if (__n > 0) 14444684ddb6SLionel Sambuc __append(__n, __v); 14454684ddb6SLionel Sambuc} 14464684ddb6SLionel Sambuc 14474684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14484684ddb6SLionel Sambuctemplate <class _InputIter> 14494684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, 14504684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value>::type*) 14514684ddb6SLionel Sambuc{ 14524684ddb6SLionel Sambuc __append(__f, __l); 14534684ddb6SLionel Sambuc} 14544684ddb6SLionel Sambuc 14554684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14564684ddb6SLionel Sambuctemplate <class _InputIter> 14574684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, 14584684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value>::type*) 14594684ddb6SLionel Sambuc : __base(__a) 14604684ddb6SLionel Sambuc{ 14614684ddb6SLionel Sambuc __append(__f, __l); 14624684ddb6SLionel Sambuc} 14634684ddb6SLionel Sambuc 14644684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14654684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(const deque& __c) 14664684ddb6SLionel Sambuc : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) 14674684ddb6SLionel Sambuc{ 14684684ddb6SLionel Sambuc __append(__c.begin(), __c.end()); 14694684ddb6SLionel Sambuc} 14704684ddb6SLionel Sambuc 14714684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14724684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) 14734684ddb6SLionel Sambuc : __base(__a) 14744684ddb6SLionel Sambuc{ 14754684ddb6SLionel Sambuc __append(__c.begin(), __c.end()); 14764684ddb6SLionel Sambuc} 14774684ddb6SLionel Sambuc 14784684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 14794684ddb6SLionel Sambuc 14804684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14814684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) 14824684ddb6SLionel Sambuc{ 14834684ddb6SLionel Sambuc __append(__il.begin(), __il.end()); 14844684ddb6SLionel Sambuc} 14854684ddb6SLionel Sambuc 14864684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14874684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) 14884684ddb6SLionel Sambuc : __base(__a) 14894684ddb6SLionel Sambuc{ 14904684ddb6SLionel Sambuc __append(__il.begin(), __il.end()); 14914684ddb6SLionel Sambuc} 14924684ddb6SLionel Sambuc 14934684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 14944684ddb6SLionel Sambuc 14954684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14964684ddb6SLionel Sambucdeque<_Tp, _Allocator>& 14974684ddb6SLionel Sambucdeque<_Tp, _Allocator>::operator=(const deque& __c) 14984684ddb6SLionel Sambuc{ 14994684ddb6SLionel Sambuc if (this != &__c) 15004684ddb6SLionel Sambuc { 15014684ddb6SLionel Sambuc __copy_assign_alloc(__c); 15024684ddb6SLionel Sambuc assign(__c.begin(), __c.end()); 15034684ddb6SLionel Sambuc } 15044684ddb6SLionel Sambuc return *this; 15054684ddb6SLionel Sambuc} 15064684ddb6SLionel Sambuc 15074684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15084684ddb6SLionel Sambuc 15094684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15104684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15114684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(deque&& __c) 15124684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 15134684ddb6SLionel Sambuc : __base(_VSTD::move(__c)) 15144684ddb6SLionel Sambuc{ 15154684ddb6SLionel Sambuc} 15164684ddb6SLionel Sambuc 15174684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15194684ddb6SLionel Sambucdeque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) 15204684ddb6SLionel Sambuc : __base(_VSTD::move(__c), __a) 15214684ddb6SLionel Sambuc{ 15224684ddb6SLionel Sambuc if (__a != __c.__alloc()) 15234684ddb6SLionel Sambuc { 15244684ddb6SLionel Sambuc typedef move_iterator<iterator> _Ip; 15254684ddb6SLionel Sambuc assign(_Ip(__c.begin()), _Ip(__c.end())); 15264684ddb6SLionel Sambuc } 15274684ddb6SLionel Sambuc} 15284684ddb6SLionel Sambuc 15294684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15304684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15314684ddb6SLionel Sambucdeque<_Tp, _Allocator>& 15324684ddb6SLionel Sambucdeque<_Tp, _Allocator>::operator=(deque&& __c) 15334684ddb6SLionel Sambuc _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 15344684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value) 15354684ddb6SLionel Sambuc{ 15364684ddb6SLionel Sambuc __move_assign(__c, integral_constant<bool, 15374684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_move_assignment::value>()); 15384684ddb6SLionel Sambuc return *this; 15394684ddb6SLionel Sambuc} 15404684ddb6SLionel Sambuc 15414684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15424684ddb6SLionel Sambucvoid 15434684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) 15444684ddb6SLionel Sambuc{ 15454684ddb6SLionel Sambuc if (__base::__alloc() != __c.__alloc()) 15464684ddb6SLionel Sambuc { 15474684ddb6SLionel Sambuc typedef move_iterator<iterator> _Ip; 15484684ddb6SLionel Sambuc assign(_Ip(__c.begin()), _Ip(__c.end())); 15494684ddb6SLionel Sambuc } 15504684ddb6SLionel Sambuc else 15514684ddb6SLionel Sambuc __move_assign(__c, true_type()); 15524684ddb6SLionel Sambuc} 15534684ddb6SLionel Sambuc 15544684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15554684ddb6SLionel Sambucvoid 15564684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) 15574684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 15584684ddb6SLionel Sambuc{ 15594684ddb6SLionel Sambuc clear(); 15604684ddb6SLionel Sambuc shrink_to_fit(); 15614684ddb6SLionel Sambuc __base::__move_assign(__c); 15624684ddb6SLionel Sambuc} 15634684ddb6SLionel Sambuc 15644684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 15654684ddb6SLionel Sambuc 15664684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15674684ddb6SLionel Sambuctemplate <class _InputIter> 15684684ddb6SLionel Sambucvoid 15694684ddb6SLionel Sambucdeque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, 15704684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value && 15714684ddb6SLionel Sambuc !__is_random_access_iterator<_InputIter>::value>::type*) 15724684ddb6SLionel Sambuc{ 15734684ddb6SLionel Sambuc iterator __i = __base::begin(); 15744684ddb6SLionel Sambuc iterator __e = __base::end(); 1575*0a6a1f1dSLionel Sambuc for (; __f != __l && __i != __e; ++__f, (void) ++__i) 15764684ddb6SLionel Sambuc *__i = *__f; 15774684ddb6SLionel Sambuc if (__f != __l) 15784684ddb6SLionel Sambuc __append(__f, __l); 15794684ddb6SLionel Sambuc else 15804684ddb6SLionel Sambuc __erase_to_end(__i); 15814684ddb6SLionel Sambuc} 15824684ddb6SLionel Sambuc 15834684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15844684ddb6SLionel Sambuctemplate <class _RAIter> 15854684ddb6SLionel Sambucvoid 15864684ddb6SLionel Sambucdeque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, 15874684ddb6SLionel Sambuc typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) 15884684ddb6SLionel Sambuc{ 15894684ddb6SLionel Sambuc if (static_cast<size_type>(__l - __f) > __base::size()) 15904684ddb6SLionel Sambuc { 15914684ddb6SLionel Sambuc _RAIter __m = __f + __base::size(); 15924684ddb6SLionel Sambuc _VSTD::copy(__f, __m, __base::begin()); 15934684ddb6SLionel Sambuc __append(__m, __l); 15944684ddb6SLionel Sambuc } 15954684ddb6SLionel Sambuc else 15964684ddb6SLionel Sambuc __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); 15974684ddb6SLionel Sambuc} 15984684ddb6SLionel Sambuc 15994684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16004684ddb6SLionel Sambucvoid 16014684ddb6SLionel Sambucdeque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) 16024684ddb6SLionel Sambuc{ 16034684ddb6SLionel Sambuc if (__n > __base::size()) 16044684ddb6SLionel Sambuc { 16054684ddb6SLionel Sambuc _VSTD::fill_n(__base::begin(), __base::size(), __v); 16064684ddb6SLionel Sambuc __n -= __base::size(); 16074684ddb6SLionel Sambuc __append(__n, __v); 16084684ddb6SLionel Sambuc } 16094684ddb6SLionel Sambuc else 16104684ddb6SLionel Sambuc __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); 16114684ddb6SLionel Sambuc} 16124684ddb6SLionel Sambuc 16134684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16144684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16154684ddb6SLionel Sambuc_Allocator 16164684ddb6SLionel Sambucdeque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT 16174684ddb6SLionel Sambuc{ 16184684ddb6SLionel Sambuc return __base::__alloc(); 16194684ddb6SLionel Sambuc} 16204684ddb6SLionel Sambuc 16214684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16224684ddb6SLionel Sambucvoid 16234684ddb6SLionel Sambucdeque<_Tp, _Allocator>::resize(size_type __n) 16244684ddb6SLionel Sambuc{ 16254684ddb6SLionel Sambuc if (__n > __base::size()) 16264684ddb6SLionel Sambuc __append(__n - __base::size()); 16274684ddb6SLionel Sambuc else if (__n < __base::size()) 16284684ddb6SLionel Sambuc __erase_to_end(__base::begin() + __n); 16294684ddb6SLionel Sambuc} 16304684ddb6SLionel Sambuc 16314684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16324684ddb6SLionel Sambucvoid 16334684ddb6SLionel Sambucdeque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) 16344684ddb6SLionel Sambuc{ 16354684ddb6SLionel Sambuc if (__n > __base::size()) 16364684ddb6SLionel Sambuc __append(__n - __base::size(), __v); 16374684ddb6SLionel Sambuc else if (__n < __base::size()) 16384684ddb6SLionel Sambuc __erase_to_end(__base::begin() + __n); 16394684ddb6SLionel Sambuc} 16404684ddb6SLionel Sambuc 16414684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16424684ddb6SLionel Sambucvoid 16434684ddb6SLionel Sambucdeque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 16444684ddb6SLionel Sambuc{ 16454684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 16464684ddb6SLionel Sambuc if (empty()) 16474684ddb6SLionel Sambuc { 16484684ddb6SLionel Sambuc while (__base::__map_.size() > 0) 16494684ddb6SLionel Sambuc { 16504684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 16514684ddb6SLionel Sambuc __base::__map_.pop_back(); 16524684ddb6SLionel Sambuc } 16534684ddb6SLionel Sambuc __base::__start_ = 0; 16544684ddb6SLionel Sambuc } 16554684ddb6SLionel Sambuc else 16564684ddb6SLionel Sambuc { 16574684ddb6SLionel Sambuc if (__front_spare() >= __base::__block_size) 16584684ddb6SLionel Sambuc { 16594684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); 16604684ddb6SLionel Sambuc __base::__map_.pop_front(); 16614684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size; 16624684ddb6SLionel Sambuc } 16634684ddb6SLionel Sambuc if (__back_spare() >= __base::__block_size) 16644684ddb6SLionel Sambuc { 16654684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 16664684ddb6SLionel Sambuc __base::__map_.pop_back(); 16674684ddb6SLionel Sambuc } 16684684ddb6SLionel Sambuc } 16694684ddb6SLionel Sambuc __base::__map_.shrink_to_fit(); 16704684ddb6SLionel Sambuc} 16714684ddb6SLionel Sambuc 16724684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16734684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16744684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::reference 16754684ddb6SLionel Sambucdeque<_Tp, _Allocator>::operator[](size_type __i) 16764684ddb6SLionel Sambuc{ 16774684ddb6SLionel Sambuc size_type __p = __base::__start_ + __i; 16784684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 16794684ddb6SLionel Sambuc} 16804684ddb6SLionel Sambuc 16814684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16824684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16834684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::const_reference 16844684ddb6SLionel Sambucdeque<_Tp, _Allocator>::operator[](size_type __i) const 16854684ddb6SLionel Sambuc{ 16864684ddb6SLionel Sambuc size_type __p = __base::__start_ + __i; 16874684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 16884684ddb6SLionel Sambuc} 16894684ddb6SLionel Sambuc 16904684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16914684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16924684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::reference 16934684ddb6SLionel Sambucdeque<_Tp, _Allocator>::at(size_type __i) 16944684ddb6SLionel Sambuc{ 16954684ddb6SLionel Sambuc if (__i >= __base::size()) 16964684ddb6SLionel Sambuc __base::__throw_out_of_range(); 16974684ddb6SLionel Sambuc size_type __p = __base::__start_ + __i; 16984684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 16994684ddb6SLionel Sambuc} 17004684ddb6SLionel Sambuc 17014684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17024684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17034684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::const_reference 17044684ddb6SLionel Sambucdeque<_Tp, _Allocator>::at(size_type __i) const 17054684ddb6SLionel Sambuc{ 17064684ddb6SLionel Sambuc if (__i >= __base::size()) 17074684ddb6SLionel Sambuc __base::__throw_out_of_range(); 17084684ddb6SLionel Sambuc size_type __p = __base::__start_ + __i; 17094684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 17104684ddb6SLionel Sambuc} 17114684ddb6SLionel Sambuc 17124684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17134684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17144684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::reference 17154684ddb6SLionel Sambucdeque<_Tp, _Allocator>::front() 17164684ddb6SLionel Sambuc{ 17174684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) 17184684ddb6SLionel Sambuc + __base::__start_ % __base::__block_size); 17194684ddb6SLionel Sambuc} 17204684ddb6SLionel Sambuc 17214684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17224684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17234684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::const_reference 17244684ddb6SLionel Sambucdeque<_Tp, _Allocator>::front() const 17254684ddb6SLionel Sambuc{ 17264684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) 17274684ddb6SLionel Sambuc + __base::__start_ % __base::__block_size); 17284684ddb6SLionel Sambuc} 17294684ddb6SLionel Sambuc 17304684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17314684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17324684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::reference 17334684ddb6SLionel Sambucdeque<_Tp, _Allocator>::back() 17344684ddb6SLionel Sambuc{ 17354684ddb6SLionel Sambuc size_type __p = __base::size() + __base::__start_ - 1; 17364684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 17374684ddb6SLionel Sambuc} 17384684ddb6SLionel Sambuc 17394684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17404684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 17414684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::const_reference 17424684ddb6SLionel Sambucdeque<_Tp, _Allocator>::back() const 17434684ddb6SLionel Sambuc{ 17444684ddb6SLionel Sambuc size_type __p = __base::size() + __base::__start_ - 1; 17454684ddb6SLionel Sambuc return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); 17464684ddb6SLionel Sambuc} 17474684ddb6SLionel Sambuc 17484684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17494684ddb6SLionel Sambucvoid 17504684ddb6SLionel Sambucdeque<_Tp, _Allocator>::push_back(const value_type& __v) 17514684ddb6SLionel Sambuc{ 17524684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 17534684ddb6SLionel Sambuc if (__back_spare() == 0) 17544684ddb6SLionel Sambuc __add_back_capacity(); 17554684ddb6SLionel Sambuc // __back_spare() >= 1 17564684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); 17574684ddb6SLionel Sambuc ++__base::size(); 17584684ddb6SLionel Sambuc} 17594684ddb6SLionel Sambuc 17604684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 17614684ddb6SLionel Sambuc 17624684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17634684ddb6SLionel Sambucvoid 17644684ddb6SLionel Sambucdeque<_Tp, _Allocator>::push_back(value_type&& __v) 17654684ddb6SLionel Sambuc{ 17664684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 17674684ddb6SLionel Sambuc if (__back_spare() == 0) 17684684ddb6SLionel Sambuc __add_back_capacity(); 17694684ddb6SLionel Sambuc // __back_spare() >= 1 17704684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); 17714684ddb6SLionel Sambuc ++__base::size(); 17724684ddb6SLionel Sambuc} 17734684ddb6SLionel Sambuc 17744684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 17754684ddb6SLionel Sambuc 17764684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17774684ddb6SLionel Sambuctemplate <class... _Args> 17784684ddb6SLionel Sambucvoid 17794684ddb6SLionel Sambucdeque<_Tp, _Allocator>::emplace_back(_Args&&... __args) 17804684ddb6SLionel Sambuc{ 17814684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 17824684ddb6SLionel Sambuc if (__back_spare() == 0) 17834684ddb6SLionel Sambuc __add_back_capacity(); 17844684ddb6SLionel Sambuc // __back_spare() >= 1 17854684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); 17864684ddb6SLionel Sambuc ++__base::size(); 17874684ddb6SLionel Sambuc} 17884684ddb6SLionel Sambuc 17894684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 17904684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 17914684ddb6SLionel Sambuc 17924684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17934684ddb6SLionel Sambucvoid 17944684ddb6SLionel Sambucdeque<_Tp, _Allocator>::push_front(const value_type& __v) 17954684ddb6SLionel Sambuc{ 17964684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 17974684ddb6SLionel Sambuc if (__front_spare() == 0) 17984684ddb6SLionel Sambuc __add_front_capacity(); 17994684ddb6SLionel Sambuc // __front_spare() >= 1 18004684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); 18014684ddb6SLionel Sambuc --__base::__start_; 18024684ddb6SLionel Sambuc ++__base::size(); 18034684ddb6SLionel Sambuc} 18044684ddb6SLionel Sambuc 18054684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 18064684ddb6SLionel Sambuc 18074684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 18084684ddb6SLionel Sambucvoid 18094684ddb6SLionel Sambucdeque<_Tp, _Allocator>::push_front(value_type&& __v) 18104684ddb6SLionel Sambuc{ 18114684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 18124684ddb6SLionel Sambuc if (__front_spare() == 0) 18134684ddb6SLionel Sambuc __add_front_capacity(); 18144684ddb6SLionel Sambuc // __front_spare() >= 1 18154684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); 18164684ddb6SLionel Sambuc --__base::__start_; 18174684ddb6SLionel Sambuc ++__base::size(); 18184684ddb6SLionel Sambuc} 18194684ddb6SLionel Sambuc 18204684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 18214684ddb6SLionel Sambuc 18224684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 18234684ddb6SLionel Sambuctemplate <class... _Args> 18244684ddb6SLionel Sambucvoid 18254684ddb6SLionel Sambucdeque<_Tp, _Allocator>::emplace_front(_Args&&... __args) 18264684ddb6SLionel Sambuc{ 18274684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 18284684ddb6SLionel Sambuc if (__front_spare() == 0) 18294684ddb6SLionel Sambuc __add_front_capacity(); 18304684ddb6SLionel Sambuc // __front_spare() >= 1 18314684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); 18324684ddb6SLionel Sambuc --__base::__start_; 18334684ddb6SLionel Sambuc ++__base::size(); 18344684ddb6SLionel Sambuc} 18354684ddb6SLionel Sambuc 18364684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 18374684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 18384684ddb6SLionel Sambuc 18394684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 18404684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 18414684ddb6SLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) 18424684ddb6SLionel Sambuc{ 18434684ddb6SLionel Sambuc size_type __pos = __p - __base::begin(); 18444684ddb6SLionel Sambuc size_type __to_end = __base::size() - __pos; 18454684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 18464684ddb6SLionel Sambuc if (__pos < __to_end) 18474684ddb6SLionel Sambuc { // insert by shifting things backward 18484684ddb6SLionel Sambuc if (__front_spare() == 0) 18494684ddb6SLionel Sambuc __add_front_capacity(); 18504684ddb6SLionel Sambuc // __front_spare() >= 1 18514684ddb6SLionel Sambuc if (__pos == 0) 18524684ddb6SLionel Sambuc { 18534684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); 18544684ddb6SLionel Sambuc --__base::__start_; 18554684ddb6SLionel Sambuc ++__base::size(); 18564684ddb6SLionel Sambuc } 18574684ddb6SLionel Sambuc else 18584684ddb6SLionel Sambuc { 18594684ddb6SLionel Sambuc const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 18604684ddb6SLionel Sambuc iterator __b = __base::begin(); 18614684ddb6SLionel Sambuc iterator __bm1 = _VSTD::prev(__b); 18624684ddb6SLionel Sambuc if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) 18634684ddb6SLionel Sambuc __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); 18644684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 18654684ddb6SLionel Sambuc --__base::__start_; 18664684ddb6SLionel Sambuc ++__base::size(); 18674684ddb6SLionel Sambuc if (__pos > 1) 18684684ddb6SLionel Sambuc __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); 18694684ddb6SLionel Sambuc *__b = *__vt; 18704684ddb6SLionel Sambuc } 18714684ddb6SLionel Sambuc } 18724684ddb6SLionel Sambuc else 18734684ddb6SLionel Sambuc { // insert by shifting things forward 18744684ddb6SLionel Sambuc if (__back_spare() == 0) 18754684ddb6SLionel Sambuc __add_back_capacity(); 18764684ddb6SLionel Sambuc // __back_capacity >= 1 18774684ddb6SLionel Sambuc size_type __de = __base::size() - __pos; 18784684ddb6SLionel Sambuc if (__de == 0) 18794684ddb6SLionel Sambuc { 18804684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); 18814684ddb6SLionel Sambuc ++__base::size(); 18824684ddb6SLionel Sambuc } 18834684ddb6SLionel Sambuc else 18844684ddb6SLionel Sambuc { 18854684ddb6SLionel Sambuc const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 18864684ddb6SLionel Sambuc iterator __e = __base::end(); 18874684ddb6SLionel Sambuc iterator __em1 = _VSTD::prev(__e); 18884684ddb6SLionel Sambuc if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) 18894684ddb6SLionel Sambuc __vt = pointer_traits<const_pointer>::pointer_to(*__e); 18904684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 18914684ddb6SLionel Sambuc ++__base::size(); 18924684ddb6SLionel Sambuc if (__de > 1) 18934684ddb6SLionel Sambuc __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); 18944684ddb6SLionel Sambuc *--__e = *__vt; 18954684ddb6SLionel Sambuc } 18964684ddb6SLionel Sambuc } 18974684ddb6SLionel Sambuc return __base::begin() + __pos; 18984684ddb6SLionel Sambuc} 18994684ddb6SLionel Sambuc 19004684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 19014684ddb6SLionel Sambuc 19024684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 19034684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 19044684ddb6SLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) 19054684ddb6SLionel Sambuc{ 19064684ddb6SLionel Sambuc size_type __pos = __p - __base::begin(); 19074684ddb6SLionel Sambuc size_type __to_end = __base::size() - __pos; 19084684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 19094684ddb6SLionel Sambuc if (__pos < __to_end) 19104684ddb6SLionel Sambuc { // insert by shifting things backward 19114684ddb6SLionel Sambuc if (__front_spare() == 0) 19124684ddb6SLionel Sambuc __add_front_capacity(); 19134684ddb6SLionel Sambuc // __front_spare() >= 1 19144684ddb6SLionel Sambuc if (__pos == 0) 19154684ddb6SLionel Sambuc { 19164684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); 19174684ddb6SLionel Sambuc --__base::__start_; 19184684ddb6SLionel Sambuc ++__base::size(); 19194684ddb6SLionel Sambuc } 19204684ddb6SLionel Sambuc else 19214684ddb6SLionel Sambuc { 19224684ddb6SLionel Sambuc iterator __b = __base::begin(); 19234684ddb6SLionel Sambuc iterator __bm1 = _VSTD::prev(__b); 19244684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 19254684ddb6SLionel Sambuc --__base::__start_; 19264684ddb6SLionel Sambuc ++__base::size(); 19274684ddb6SLionel Sambuc if (__pos > 1) 19284684ddb6SLionel Sambuc __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); 19294684ddb6SLionel Sambuc *__b = _VSTD::move(__v); 19304684ddb6SLionel Sambuc } 19314684ddb6SLionel Sambuc } 19324684ddb6SLionel Sambuc else 19334684ddb6SLionel Sambuc { // insert by shifting things forward 19344684ddb6SLionel Sambuc if (__back_spare() == 0) 19354684ddb6SLionel Sambuc __add_back_capacity(); 19364684ddb6SLionel Sambuc // __back_capacity >= 1 19374684ddb6SLionel Sambuc size_type __de = __base::size() - __pos; 19384684ddb6SLionel Sambuc if (__de == 0) 19394684ddb6SLionel Sambuc { 19404684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); 19414684ddb6SLionel Sambuc ++__base::size(); 19424684ddb6SLionel Sambuc } 19434684ddb6SLionel Sambuc else 19444684ddb6SLionel Sambuc { 19454684ddb6SLionel Sambuc iterator __e = __base::end(); 19464684ddb6SLionel Sambuc iterator __em1 = _VSTD::prev(__e); 19474684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 19484684ddb6SLionel Sambuc ++__base::size(); 19494684ddb6SLionel Sambuc if (__de > 1) 19504684ddb6SLionel Sambuc __e = _VSTD::move_backward(__e - __de, __em1, __e); 19514684ddb6SLionel Sambuc *--__e = _VSTD::move(__v); 19524684ddb6SLionel Sambuc } 19534684ddb6SLionel Sambuc } 19544684ddb6SLionel Sambuc return __base::begin() + __pos; 19554684ddb6SLionel Sambuc} 19564684ddb6SLionel Sambuc 19574684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 19584684ddb6SLionel Sambuc 19594684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 19604684ddb6SLionel Sambuctemplate <class... _Args> 19614684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 19624684ddb6SLionel Sambucdeque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) 19634684ddb6SLionel Sambuc{ 19644684ddb6SLionel Sambuc size_type __pos = __p - __base::begin(); 19654684ddb6SLionel Sambuc size_type __to_end = __base::size() - __pos; 19664684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 19674684ddb6SLionel Sambuc if (__pos < __to_end) 19684684ddb6SLionel Sambuc { // insert by shifting things backward 19694684ddb6SLionel Sambuc if (__front_spare() == 0) 19704684ddb6SLionel Sambuc __add_front_capacity(); 19714684ddb6SLionel Sambuc // __front_spare() >= 1 19724684ddb6SLionel Sambuc if (__pos == 0) 19734684ddb6SLionel Sambuc { 19744684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); 19754684ddb6SLionel Sambuc --__base::__start_; 19764684ddb6SLionel Sambuc ++__base::size(); 19774684ddb6SLionel Sambuc } 19784684ddb6SLionel Sambuc else 19794684ddb6SLionel Sambuc { 19804684ddb6SLionel Sambuc value_type __tmp(_VSTD::forward<_Args>(__args)...); 19814684ddb6SLionel Sambuc iterator __b = __base::begin(); 19824684ddb6SLionel Sambuc iterator __bm1 = _VSTD::prev(__b); 19834684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); 19844684ddb6SLionel Sambuc --__base::__start_; 19854684ddb6SLionel Sambuc ++__base::size(); 19864684ddb6SLionel Sambuc if (__pos > 1) 19874684ddb6SLionel Sambuc __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); 19884684ddb6SLionel Sambuc *__b = _VSTD::move(__tmp); 19894684ddb6SLionel Sambuc } 19904684ddb6SLionel Sambuc } 19914684ddb6SLionel Sambuc else 19924684ddb6SLionel Sambuc { // insert by shifting things forward 19934684ddb6SLionel Sambuc if (__back_spare() == 0) 19944684ddb6SLionel Sambuc __add_back_capacity(); 19954684ddb6SLionel Sambuc // __back_capacity >= 1 19964684ddb6SLionel Sambuc size_type __de = __base::size() - __pos; 19974684ddb6SLionel Sambuc if (__de == 0) 19984684ddb6SLionel Sambuc { 19994684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); 20004684ddb6SLionel Sambuc ++__base::size(); 20014684ddb6SLionel Sambuc } 20024684ddb6SLionel Sambuc else 20034684ddb6SLionel Sambuc { 20044684ddb6SLionel Sambuc value_type __tmp(_VSTD::forward<_Args>(__args)...); 20054684ddb6SLionel Sambuc iterator __e = __base::end(); 20064684ddb6SLionel Sambuc iterator __em1 = _VSTD::prev(__e); 20074684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); 20084684ddb6SLionel Sambuc ++__base::size(); 20094684ddb6SLionel Sambuc if (__de > 1) 20104684ddb6SLionel Sambuc __e = _VSTD::move_backward(__e - __de, __em1, __e); 20114684ddb6SLionel Sambuc *--__e = _VSTD::move(__tmp); 20124684ddb6SLionel Sambuc } 20134684ddb6SLionel Sambuc } 20144684ddb6SLionel Sambuc return __base::begin() + __pos; 20154684ddb6SLionel Sambuc} 20164684ddb6SLionel Sambuc 20174684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 20184684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 20194684ddb6SLionel Sambuc 20204684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20214684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 20224684ddb6SLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) 20234684ddb6SLionel Sambuc{ 20244684ddb6SLionel Sambuc size_type __pos = __p - __base::begin(); 20254684ddb6SLionel Sambuc size_type __to_end = __base::size() - __pos; 20264684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 20274684ddb6SLionel Sambuc if (__pos < __to_end) 20284684ddb6SLionel Sambuc { // insert by shifting things backward 20294684ddb6SLionel Sambuc if (__n > __front_spare()) 20304684ddb6SLionel Sambuc __add_front_capacity(__n - __front_spare()); 20314684ddb6SLionel Sambuc // __n <= __front_spare() 20324684ddb6SLionel Sambuc iterator __old_begin = __base::begin(); 20334684ddb6SLionel Sambuc iterator __i = __old_begin; 20344684ddb6SLionel Sambuc if (__n > __pos) 20354684ddb6SLionel Sambuc { 20364684ddb6SLionel Sambuc for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) 20374684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); 20384684ddb6SLionel Sambuc __n = __pos; 20394684ddb6SLionel Sambuc } 20404684ddb6SLionel Sambuc if (__n > 0) 20414684ddb6SLionel Sambuc { 20424684ddb6SLionel Sambuc const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 20434684ddb6SLionel Sambuc iterator __obn = __old_begin + __n; 20444684ddb6SLionel Sambuc __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); 20454684ddb6SLionel Sambuc if (__n < __pos) 20464684ddb6SLionel Sambuc __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); 20474684ddb6SLionel Sambuc _VSTD::fill_n(__old_begin, __n, *__vt); 20484684ddb6SLionel Sambuc } 20494684ddb6SLionel Sambuc } 20504684ddb6SLionel Sambuc else 20514684ddb6SLionel Sambuc { // insert by shifting things forward 20524684ddb6SLionel Sambuc size_type __back_capacity = __back_spare(); 20534684ddb6SLionel Sambuc if (__n > __back_capacity) 20544684ddb6SLionel Sambuc __add_back_capacity(__n - __back_capacity); 20554684ddb6SLionel Sambuc // __n <= __back_capacity 20564684ddb6SLionel Sambuc iterator __old_end = __base::end(); 20574684ddb6SLionel Sambuc iterator __i = __old_end; 20584684ddb6SLionel Sambuc size_type __de = __base::size() - __pos; 20594684ddb6SLionel Sambuc if (__n > __de) 20604684ddb6SLionel Sambuc { 20614684ddb6SLionel Sambuc for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) 20624684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); 20634684ddb6SLionel Sambuc __n = __de; 20644684ddb6SLionel Sambuc } 20654684ddb6SLionel Sambuc if (__n > 0) 20664684ddb6SLionel Sambuc { 20674684ddb6SLionel Sambuc const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); 20684684ddb6SLionel Sambuc iterator __oen = __old_end - __n; 20694684ddb6SLionel Sambuc __move_construct_and_check(__oen, __old_end, __i, __vt); 20704684ddb6SLionel Sambuc if (__n < __de) 20714684ddb6SLionel Sambuc __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); 20724684ddb6SLionel Sambuc _VSTD::fill_n(__old_end - __n, __n, *__vt); 20734684ddb6SLionel Sambuc } 20744684ddb6SLionel Sambuc } 20754684ddb6SLionel Sambuc return __base::begin() + __pos; 20764684ddb6SLionel Sambuc} 20774684ddb6SLionel Sambuc 20784684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20794684ddb6SLionel Sambuctemplate <class _InputIter> 20804684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 20814684ddb6SLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, 20824684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InputIter>::value 2083*0a6a1f1dSLionel Sambuc &&!__is_forward_iterator<_InputIter>::value>::type*) 20844684ddb6SLionel Sambuc{ 20854684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); 20864684ddb6SLionel Sambuc __buf.__construct_at_end(__f, __l); 20874684ddb6SLionel Sambuc typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; 20884684ddb6SLionel Sambuc return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); 20894684ddb6SLionel Sambuc} 20904684ddb6SLionel Sambuc 20914684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 2092*0a6a1f1dSLionel Sambuctemplate <class _ForwardIterator> 2093*0a6a1f1dSLionel Sambuctypename deque<_Tp, _Allocator>::iterator 2094*0a6a1f1dSLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, 2095*0a6a1f1dSLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value 2096*0a6a1f1dSLionel Sambuc &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*) 2097*0a6a1f1dSLionel Sambuc{ 2098*0a6a1f1dSLionel Sambuc size_type __n = _VSTD::distance(__f, __l); 2099*0a6a1f1dSLionel Sambuc __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); 2100*0a6a1f1dSLionel Sambuc __buf.__construct_at_end(__f, __l); 2101*0a6a1f1dSLionel Sambuc typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; 2102*0a6a1f1dSLionel Sambuc return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); 2103*0a6a1f1dSLionel Sambuc} 2104*0a6a1f1dSLionel Sambuc 2105*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Allocator> 21064684ddb6SLionel Sambuctemplate <class _BiIter> 21074684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 21084684ddb6SLionel Sambucdeque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, 21094684ddb6SLionel Sambuc typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) 21104684ddb6SLionel Sambuc{ 21114684ddb6SLionel Sambuc size_type __n = _VSTD::distance(__f, __l); 21124684ddb6SLionel Sambuc size_type __pos = __p - __base::begin(); 21134684ddb6SLionel Sambuc size_type __to_end = __base::size() - __pos; 21144684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 21154684ddb6SLionel Sambuc if (__pos < __to_end) 21164684ddb6SLionel Sambuc { // insert by shifting things backward 21174684ddb6SLionel Sambuc if (__n > __front_spare()) 21184684ddb6SLionel Sambuc __add_front_capacity(__n - __front_spare()); 21194684ddb6SLionel Sambuc // __n <= __front_spare() 21204684ddb6SLionel Sambuc iterator __old_begin = __base::begin(); 21214684ddb6SLionel Sambuc iterator __i = __old_begin; 21224684ddb6SLionel Sambuc _BiIter __m = __f; 21234684ddb6SLionel Sambuc if (__n > __pos) 21244684ddb6SLionel Sambuc { 21254684ddb6SLionel Sambuc __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); 21264684ddb6SLionel Sambuc for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) 21274684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); 21284684ddb6SLionel Sambuc __n = __pos; 21294684ddb6SLionel Sambuc } 21304684ddb6SLionel Sambuc if (__n > 0) 21314684ddb6SLionel Sambuc { 21324684ddb6SLionel Sambuc iterator __obn = __old_begin + __n; 21334684ddb6SLionel Sambuc for (iterator __j = __obn; __j != __old_begin;) 21344684ddb6SLionel Sambuc { 21354684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); 21364684ddb6SLionel Sambuc --__base::__start_; 21374684ddb6SLionel Sambuc ++__base::size(); 21384684ddb6SLionel Sambuc } 21394684ddb6SLionel Sambuc if (__n < __pos) 21404684ddb6SLionel Sambuc __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); 21414684ddb6SLionel Sambuc _VSTD::copy(__m, __l, __old_begin); 21424684ddb6SLionel Sambuc } 21434684ddb6SLionel Sambuc } 21444684ddb6SLionel Sambuc else 21454684ddb6SLionel Sambuc { // insert by shifting things forward 21464684ddb6SLionel Sambuc size_type __back_capacity = __back_spare(); 21474684ddb6SLionel Sambuc if (__n > __back_capacity) 21484684ddb6SLionel Sambuc __add_back_capacity(__n - __back_capacity); 21494684ddb6SLionel Sambuc // __n <= __back_capacity 21504684ddb6SLionel Sambuc iterator __old_end = __base::end(); 21514684ddb6SLionel Sambuc iterator __i = __old_end; 21524684ddb6SLionel Sambuc _BiIter __m = __l; 21534684ddb6SLionel Sambuc size_type __de = __base::size() - __pos; 21544684ddb6SLionel Sambuc if (__n > __de) 21554684ddb6SLionel Sambuc { 21564684ddb6SLionel Sambuc __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); 2157*0a6a1f1dSLionel Sambuc for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) 21584684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); 21594684ddb6SLionel Sambuc __n = __de; 21604684ddb6SLionel Sambuc } 21614684ddb6SLionel Sambuc if (__n > 0) 21624684ddb6SLionel Sambuc { 21634684ddb6SLionel Sambuc iterator __oen = __old_end - __n; 21644684ddb6SLionel Sambuc for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) 21654684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); 21664684ddb6SLionel Sambuc if (__n < __de) 21674684ddb6SLionel Sambuc __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); 21684684ddb6SLionel Sambuc _VSTD::copy_backward(__f, __m, __old_end); 21694684ddb6SLionel Sambuc } 21704684ddb6SLionel Sambuc } 21714684ddb6SLionel Sambuc return __base::begin() + __pos; 21724684ddb6SLionel Sambuc} 21734684ddb6SLionel Sambuc 21744684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 21754684ddb6SLionel Sambuctemplate <class _InpIter> 21764684ddb6SLionel Sambucvoid 21774684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, 21784684ddb6SLionel Sambuc typename enable_if<__is_input_iterator<_InpIter>::value && 21794684ddb6SLionel Sambuc !__is_forward_iterator<_InpIter>::value>::type*) 21804684ddb6SLionel Sambuc{ 21814684ddb6SLionel Sambuc for (; __f != __l; ++__f) 21824684ddb6SLionel Sambuc push_back(*__f); 21834684ddb6SLionel Sambuc} 21844684ddb6SLionel Sambuc 21854684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 21864684ddb6SLionel Sambuctemplate <class _ForIter> 21874684ddb6SLionel Sambucvoid 21884684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, 21894684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) 21904684ddb6SLionel Sambuc{ 21914684ddb6SLionel Sambuc size_type __n = _VSTD::distance(__f, __l); 21924684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 21934684ddb6SLionel Sambuc size_type __back_capacity = __back_spare(); 21944684ddb6SLionel Sambuc if (__n > __back_capacity) 21954684ddb6SLionel Sambuc __add_back_capacity(__n - __back_capacity); 21964684ddb6SLionel Sambuc // __n <= __back_capacity 2197*0a6a1f1dSLionel Sambuc for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size()) 21984684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); 21994684ddb6SLionel Sambuc} 22004684ddb6SLionel Sambuc 22014684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 22024684ddb6SLionel Sambucvoid 22034684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__append(size_type __n) 22044684ddb6SLionel Sambuc{ 22054684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 22064684ddb6SLionel Sambuc size_type __back_capacity = __back_spare(); 22074684ddb6SLionel Sambuc if (__n > __back_capacity) 22084684ddb6SLionel Sambuc __add_back_capacity(__n - __back_capacity); 22094684ddb6SLionel Sambuc // __n <= __back_capacity 22104684ddb6SLionel Sambuc for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) 22114684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i)); 22124684ddb6SLionel Sambuc} 22134684ddb6SLionel Sambuc 22144684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 22154684ddb6SLionel Sambucvoid 22164684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) 22174684ddb6SLionel Sambuc{ 22184684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 22194684ddb6SLionel Sambuc size_type __back_capacity = __back_spare(); 22204684ddb6SLionel Sambuc if (__n > __back_capacity) 22214684ddb6SLionel Sambuc __add_back_capacity(__n - __back_capacity); 22224684ddb6SLionel Sambuc // __n <= __back_capacity 22234684ddb6SLionel Sambuc for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) 22244684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); 22254684ddb6SLionel Sambuc} 22264684ddb6SLionel Sambuc 22274684ddb6SLionel Sambuc// Create front capacity for one block of elements. 22284684ddb6SLionel Sambuc// Strong guarantee. Either do it or don't touch anything. 22294684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 22304684ddb6SLionel Sambucvoid 22314684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__add_front_capacity() 22324684ddb6SLionel Sambuc{ 22334684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 22344684ddb6SLionel Sambuc if (__back_spare() >= __base::__block_size) 22354684ddb6SLionel Sambuc { 22364684ddb6SLionel Sambuc __base::__start_ += __base::__block_size; 22374684ddb6SLionel Sambuc pointer __pt = __base::__map_.back(); 22384684ddb6SLionel Sambuc __base::__map_.pop_back(); 22394684ddb6SLionel Sambuc __base::__map_.push_front(__pt); 22404684ddb6SLionel Sambuc } 22414684ddb6SLionel Sambuc // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer 22424684ddb6SLionel Sambuc else if (__base::__map_.size() < __base::__map_.capacity()) 22434684ddb6SLionel Sambuc { // we can put the new buffer into the map, but don't shift things around 22444684ddb6SLionel Sambuc // until all buffers are allocated. If we throw, we don't need to fix 22454684ddb6SLionel Sambuc // anything up (any added buffers are undetectible) 22464684ddb6SLionel Sambuc if (__base::__map_.__front_spare() > 0) 22474684ddb6SLionel Sambuc __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 22484684ddb6SLionel Sambuc else 22494684ddb6SLionel Sambuc { 22504684ddb6SLionel Sambuc __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 22514684ddb6SLionel Sambuc // Done allocating, reorder capacity 22524684ddb6SLionel Sambuc pointer __pt = __base::__map_.back(); 22534684ddb6SLionel Sambuc __base::__map_.pop_back(); 22544684ddb6SLionel Sambuc __base::__map_.push_front(__pt); 22554684ddb6SLionel Sambuc } 22564684ddb6SLionel Sambuc __base::__start_ = __base::__map_.size() == 1 ? 22574684ddb6SLionel Sambuc __base::__block_size / 2 : 22584684ddb6SLionel Sambuc __base::__start_ + __base::__block_size; 22594684ddb6SLionel Sambuc } 22604684ddb6SLionel Sambuc // Else need to allocate 1 buffer, *and* we need to reallocate __map_. 22614684ddb6SLionel Sambuc else 22624684ddb6SLionel Sambuc { 22634684ddb6SLionel Sambuc __split_buffer<pointer, typename __base::__pointer_allocator&> 22644684ddb6SLionel Sambuc __buf(max<size_type>(2 * __base::__map_.capacity(), 1), 22654684ddb6SLionel Sambuc 0, __base::__map_.__alloc()); 2266*0a6a1f1dSLionel Sambuc 2267*0a6a1f1dSLionel Sambuc typedef __allocator_destructor<_Allocator> _Dp; 2268*0a6a1f1dSLionel Sambuc unique_ptr<pointer, _Dp> __hold( 2269*0a6a1f1dSLionel Sambuc __alloc_traits::allocate(__a, __base::__block_size), 2270*0a6a1f1dSLionel Sambuc _Dp(__a, __base::__block_size)); 2271*0a6a1f1dSLionel Sambuc __buf.push_back(__hold.get()); 2272*0a6a1f1dSLionel Sambuc __hold.release(); 2273*0a6a1f1dSLionel Sambuc 22744684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __base::__map_.begin(); 22754684ddb6SLionel Sambuc __i != __base::__map_.end(); ++__i) 22764684ddb6SLionel Sambuc __buf.push_back(*__i); 22774684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__first_, __buf.__first_); 22784684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 22794684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_, __buf.__end_); 22804684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 22814684ddb6SLionel Sambuc __base::__start_ = __base::__map_.size() == 1 ? 22824684ddb6SLionel Sambuc __base::__block_size / 2 : 22834684ddb6SLionel Sambuc __base::__start_ + __base::__block_size; 22844684ddb6SLionel Sambuc } 22854684ddb6SLionel Sambuc} 22864684ddb6SLionel Sambuc 22874684ddb6SLionel Sambuc// Create front capacity for __n elements. 22884684ddb6SLionel Sambuc// Strong guarantee. Either do it or don't touch anything. 22894684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 22904684ddb6SLionel Sambucvoid 22914684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__add_front_capacity(size_type __n) 22924684ddb6SLionel Sambuc{ 22934684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 22944684ddb6SLionel Sambuc size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); 22954684ddb6SLionel Sambuc // Number of unused blocks at back: 22964684ddb6SLionel Sambuc size_type __back_capacity = __back_spare() / __base::__block_size; 22974684ddb6SLionel Sambuc __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need 22984684ddb6SLionel Sambuc __nb -= __back_capacity; // number of blocks need to allocate 22994684ddb6SLionel Sambuc // If __nb == 0, then we have sufficient capacity. 23004684ddb6SLionel Sambuc if (__nb == 0) 23014684ddb6SLionel Sambuc { 23024684ddb6SLionel Sambuc __base::__start_ += __base::__block_size * __back_capacity; 23034684ddb6SLionel Sambuc for (; __back_capacity > 0; --__back_capacity) 23044684ddb6SLionel Sambuc { 23054684ddb6SLionel Sambuc pointer __pt = __base::__map_.back(); 23064684ddb6SLionel Sambuc __base::__map_.pop_back(); 23074684ddb6SLionel Sambuc __base::__map_.push_front(__pt); 23084684ddb6SLionel Sambuc } 23094684ddb6SLionel Sambuc } 23104684ddb6SLionel Sambuc // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 23114684ddb6SLionel Sambuc else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) 23124684ddb6SLionel Sambuc { // we can put the new buffers into the map, but don't shift things around 23134684ddb6SLionel Sambuc // until all buffers are allocated. If we throw, we don't need to fix 23144684ddb6SLionel Sambuc // anything up (any added buffers are undetectible) 23154684ddb6SLionel Sambuc for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) 23164684ddb6SLionel Sambuc { 23174684ddb6SLionel Sambuc if (__base::__map_.__front_spare() == 0) 23184684ddb6SLionel Sambuc break; 23194684ddb6SLionel Sambuc __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 23204684ddb6SLionel Sambuc } 23214684ddb6SLionel Sambuc for (; __nb > 0; --__nb, ++__back_capacity) 23224684ddb6SLionel Sambuc __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 23234684ddb6SLionel Sambuc // Done allocating, reorder capacity 23244684ddb6SLionel Sambuc __base::__start_ += __back_capacity * __base::__block_size; 23254684ddb6SLionel Sambuc for (; __back_capacity > 0; --__back_capacity) 23264684ddb6SLionel Sambuc { 23274684ddb6SLionel Sambuc pointer __pt = __base::__map_.back(); 23284684ddb6SLionel Sambuc __base::__map_.pop_back(); 23294684ddb6SLionel Sambuc __base::__map_.push_front(__pt); 23304684ddb6SLionel Sambuc } 23314684ddb6SLionel Sambuc } 23324684ddb6SLionel Sambuc // Else need to allocate __nb buffers, *and* we need to reallocate __map_. 23334684ddb6SLionel Sambuc else 23344684ddb6SLionel Sambuc { 23354684ddb6SLionel Sambuc size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); 23364684ddb6SLionel Sambuc __split_buffer<pointer, typename __base::__pointer_allocator&> 23374684ddb6SLionel Sambuc __buf(max<size_type>(2* __base::__map_.capacity(), 23384684ddb6SLionel Sambuc __nb + __base::__map_.size()), 23394684ddb6SLionel Sambuc 0, __base::__map_.__alloc()); 23404684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 23414684ddb6SLionel Sambuc try 23424684ddb6SLionel Sambuc { 23434684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 23444684ddb6SLionel Sambuc for (; __nb > 0; --__nb) 23454684ddb6SLionel Sambuc __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 23464684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 23474684ddb6SLionel Sambuc } 23484684ddb6SLionel Sambuc catch (...) 23494684ddb6SLionel Sambuc { 23504684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __buf.begin(); 23514684ddb6SLionel Sambuc __i != __buf.end(); ++__i) 23524684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, *__i, __base::__block_size); 23534684ddb6SLionel Sambuc throw; 23544684ddb6SLionel Sambuc } 23554684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 23564684ddb6SLionel Sambuc for (; __back_capacity > 0; --__back_capacity) 23574684ddb6SLionel Sambuc { 23584684ddb6SLionel Sambuc __buf.push_back(__base::__map_.back()); 23594684ddb6SLionel Sambuc __base::__map_.pop_back(); 23604684ddb6SLionel Sambuc } 23614684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __base::__map_.begin(); 23624684ddb6SLionel Sambuc __i != __base::__map_.end(); ++__i) 23634684ddb6SLionel Sambuc __buf.push_back(*__i); 23644684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__first_, __buf.__first_); 23654684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 23664684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_, __buf.__end_); 23674684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 23684684ddb6SLionel Sambuc __base::__start_ += __ds; 23694684ddb6SLionel Sambuc } 23704684ddb6SLionel Sambuc} 23714684ddb6SLionel Sambuc 23724684ddb6SLionel Sambuc// Create back capacity for one block of elements. 23734684ddb6SLionel Sambuc// Strong guarantee. Either do it or don't touch anything. 23744684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 23754684ddb6SLionel Sambucvoid 23764684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__add_back_capacity() 23774684ddb6SLionel Sambuc{ 23784684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 23794684ddb6SLionel Sambuc if (__front_spare() >= __base::__block_size) 23804684ddb6SLionel Sambuc { 23814684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size; 23824684ddb6SLionel Sambuc pointer __pt = __base::__map_.front(); 23834684ddb6SLionel Sambuc __base::__map_.pop_front(); 23844684ddb6SLionel Sambuc __base::__map_.push_back(__pt); 23854684ddb6SLionel Sambuc } 23864684ddb6SLionel Sambuc // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 23874684ddb6SLionel Sambuc else if (__base::__map_.size() < __base::__map_.capacity()) 23884684ddb6SLionel Sambuc { // we can put the new buffer into the map, but don't shift things around 23894684ddb6SLionel Sambuc // until it is allocated. If we throw, we don't need to fix 23904684ddb6SLionel Sambuc // anything up (any added buffers are undetectible) 23914684ddb6SLionel Sambuc if (__base::__map_.__back_spare() != 0) 23924684ddb6SLionel Sambuc __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 23934684ddb6SLionel Sambuc else 23944684ddb6SLionel Sambuc { 23954684ddb6SLionel Sambuc __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 23964684ddb6SLionel Sambuc // Done allocating, reorder capacity 23974684ddb6SLionel Sambuc pointer __pt = __base::__map_.front(); 23984684ddb6SLionel Sambuc __base::__map_.pop_front(); 23994684ddb6SLionel Sambuc __base::__map_.push_back(__pt); 24004684ddb6SLionel Sambuc } 24014684ddb6SLionel Sambuc } 24024684ddb6SLionel Sambuc // Else need to allocate 1 buffer, *and* we need to reallocate __map_. 24034684ddb6SLionel Sambuc else 24044684ddb6SLionel Sambuc { 24054684ddb6SLionel Sambuc __split_buffer<pointer, typename __base::__pointer_allocator&> 24064684ddb6SLionel Sambuc __buf(max<size_type>(2* __base::__map_.capacity(), 1), 24074684ddb6SLionel Sambuc __base::__map_.size(), 24084684ddb6SLionel Sambuc __base::__map_.__alloc()); 2409*0a6a1f1dSLionel Sambuc 2410*0a6a1f1dSLionel Sambuc typedef __allocator_destructor<_Allocator> _Dp; 2411*0a6a1f1dSLionel Sambuc unique_ptr<pointer, _Dp> __hold( 2412*0a6a1f1dSLionel Sambuc __alloc_traits::allocate(__a, __base::__block_size), 2413*0a6a1f1dSLionel Sambuc _Dp(__a, __base::__block_size)); 2414*0a6a1f1dSLionel Sambuc __buf.push_back(__hold.get()); 2415*0a6a1f1dSLionel Sambuc __hold.release(); 2416*0a6a1f1dSLionel Sambuc 24174684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __base::__map_.end(); 24184684ddb6SLionel Sambuc __i != __base::__map_.begin();) 24194684ddb6SLionel Sambuc __buf.push_front(*--__i); 24204684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__first_, __buf.__first_); 24214684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 24224684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_, __buf.__end_); 24234684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 24244684ddb6SLionel Sambuc } 24254684ddb6SLionel Sambuc} 24264684ddb6SLionel Sambuc 24274684ddb6SLionel Sambuc// Create back capacity for __n elements. 24284684ddb6SLionel Sambuc// Strong guarantee. Either do it or don't touch anything. 24294684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 24304684ddb6SLionel Sambucvoid 24314684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__add_back_capacity(size_type __n) 24324684ddb6SLionel Sambuc{ 24334684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 24344684ddb6SLionel Sambuc size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); 24354684ddb6SLionel Sambuc // Number of unused blocks at front: 24364684ddb6SLionel Sambuc size_type __front_capacity = __front_spare() / __base::__block_size; 24374684ddb6SLionel Sambuc __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need 24384684ddb6SLionel Sambuc __nb -= __front_capacity; // number of blocks need to allocate 24394684ddb6SLionel Sambuc // If __nb == 0, then we have sufficient capacity. 24404684ddb6SLionel Sambuc if (__nb == 0) 24414684ddb6SLionel Sambuc { 24424684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size * __front_capacity; 24434684ddb6SLionel Sambuc for (; __front_capacity > 0; --__front_capacity) 24444684ddb6SLionel Sambuc { 24454684ddb6SLionel Sambuc pointer __pt = __base::__map_.front(); 24464684ddb6SLionel Sambuc __base::__map_.pop_front(); 24474684ddb6SLionel Sambuc __base::__map_.push_back(__pt); 24484684ddb6SLionel Sambuc } 24494684ddb6SLionel Sambuc } 24504684ddb6SLionel Sambuc // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers 24514684ddb6SLionel Sambuc else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) 24524684ddb6SLionel Sambuc { // we can put the new buffers into the map, but don't shift things around 24534684ddb6SLionel Sambuc // until all buffers are allocated. If we throw, we don't need to fix 24544684ddb6SLionel Sambuc // anything up (any added buffers are undetectible) 24554684ddb6SLionel Sambuc for (; __nb > 0; --__nb) 24564684ddb6SLionel Sambuc { 24574684ddb6SLionel Sambuc if (__base::__map_.__back_spare() == 0) 24584684ddb6SLionel Sambuc break; 24594684ddb6SLionel Sambuc __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 24604684ddb6SLionel Sambuc } 24614684ddb6SLionel Sambuc for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += 24624684ddb6SLionel Sambuc __base::__block_size - (__base::__map_.size() == 1)) 24634684ddb6SLionel Sambuc __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); 24644684ddb6SLionel Sambuc // Done allocating, reorder capacity 24654684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size * __front_capacity; 24664684ddb6SLionel Sambuc for (; __front_capacity > 0; --__front_capacity) 24674684ddb6SLionel Sambuc { 24684684ddb6SLionel Sambuc pointer __pt = __base::__map_.front(); 24694684ddb6SLionel Sambuc __base::__map_.pop_front(); 24704684ddb6SLionel Sambuc __base::__map_.push_back(__pt); 24714684ddb6SLionel Sambuc } 24724684ddb6SLionel Sambuc } 24734684ddb6SLionel Sambuc // Else need to allocate __nb buffers, *and* we need to reallocate __map_. 24744684ddb6SLionel Sambuc else 24754684ddb6SLionel Sambuc { 24764684ddb6SLionel Sambuc size_type __ds = __front_capacity * __base::__block_size; 24774684ddb6SLionel Sambuc __split_buffer<pointer, typename __base::__pointer_allocator&> 24784684ddb6SLionel Sambuc __buf(max<size_type>(2* __base::__map_.capacity(), 24794684ddb6SLionel Sambuc __nb + __base::__map_.size()), 24804684ddb6SLionel Sambuc __base::__map_.size() - __front_capacity, 24814684ddb6SLionel Sambuc __base::__map_.__alloc()); 24824684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 24834684ddb6SLionel Sambuc try 24844684ddb6SLionel Sambuc { 24854684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 24864684ddb6SLionel Sambuc for (; __nb > 0; --__nb) 24874684ddb6SLionel Sambuc __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); 24884684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 24894684ddb6SLionel Sambuc } 24904684ddb6SLionel Sambuc catch (...) 24914684ddb6SLionel Sambuc { 24924684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __buf.begin(); 24934684ddb6SLionel Sambuc __i != __buf.end(); ++__i) 24944684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, *__i, __base::__block_size); 24954684ddb6SLionel Sambuc throw; 24964684ddb6SLionel Sambuc } 24974684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 24984684ddb6SLionel Sambuc for (; __front_capacity > 0; --__front_capacity) 24994684ddb6SLionel Sambuc { 25004684ddb6SLionel Sambuc __buf.push_back(__base::__map_.front()); 25014684ddb6SLionel Sambuc __base::__map_.pop_front(); 25024684ddb6SLionel Sambuc } 25034684ddb6SLionel Sambuc for (typename __base::__map_pointer __i = __base::__map_.end(); 25044684ddb6SLionel Sambuc __i != __base::__map_.begin();) 25054684ddb6SLionel Sambuc __buf.push_front(*--__i); 25064684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__first_, __buf.__first_); 25074684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); 25084684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_, __buf.__end_); 25094684ddb6SLionel Sambuc _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); 25104684ddb6SLionel Sambuc __base::__start_ -= __ds; 25114684ddb6SLionel Sambuc } 25124684ddb6SLionel Sambuc} 25134684ddb6SLionel Sambuc 25144684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 25154684ddb6SLionel Sambucvoid 25164684ddb6SLionel Sambucdeque<_Tp, _Allocator>::pop_front() 25174684ddb6SLionel Sambuc{ 25184684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 25194684ddb6SLionel Sambuc __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + 25204684ddb6SLionel Sambuc __base::__start_ / __base::__block_size) + 25214684ddb6SLionel Sambuc __base::__start_ % __base::__block_size)); 25224684ddb6SLionel Sambuc --__base::size(); 25234684ddb6SLionel Sambuc if (++__base::__start_ >= 2 * __base::__block_size) 25244684ddb6SLionel Sambuc { 25254684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); 25264684ddb6SLionel Sambuc __base::__map_.pop_front(); 25274684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size; 25284684ddb6SLionel Sambuc } 25294684ddb6SLionel Sambuc} 25304684ddb6SLionel Sambuc 25314684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 25324684ddb6SLionel Sambucvoid 25334684ddb6SLionel Sambucdeque<_Tp, _Allocator>::pop_back() 25344684ddb6SLionel Sambuc{ 25354684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 25364684ddb6SLionel Sambuc size_type __p = __base::size() + __base::__start_ - 1; 25374684ddb6SLionel Sambuc __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + 25384684ddb6SLionel Sambuc __p / __base::__block_size) + 25394684ddb6SLionel Sambuc __p % __base::__block_size)); 25404684ddb6SLionel Sambuc --__base::size(); 25414684ddb6SLionel Sambuc if (__back_spare() >= 2 * __base::__block_size) 25424684ddb6SLionel Sambuc { 25434684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 25444684ddb6SLionel Sambuc __base::__map_.pop_back(); 25454684ddb6SLionel Sambuc } 25464684ddb6SLionel Sambuc} 25474684ddb6SLionel Sambuc 25484684ddb6SLionel Sambuc// move assign [__f, __l) to [__r, __r + (__l-__f)). 25494684ddb6SLionel Sambuc// If __vt points into [__f, __l), then subtract (__f - __r) from __vt. 25504684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 25514684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 25524684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, 25534684ddb6SLionel Sambuc const_pointer& __vt) 25544684ddb6SLionel Sambuc{ 25554684ddb6SLionel Sambuc // as if 25564684ddb6SLionel Sambuc // for (; __f != __l; ++__f, ++__r) 25574684ddb6SLionel Sambuc // *__r = _VSTD::move(*__f); 25584684ddb6SLionel Sambuc difference_type __n = __l - __f; 25594684ddb6SLionel Sambuc while (__n > 0) 25604684ddb6SLionel Sambuc { 25614684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 25624684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + __base::__block_size; 25634684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 25644684ddb6SLionel Sambuc if (__bs > __n) 25654684ddb6SLionel Sambuc { 25664684ddb6SLionel Sambuc __bs = __n; 25674684ddb6SLionel Sambuc __fe = __fb + __bs; 25684684ddb6SLionel Sambuc } 25694684ddb6SLionel Sambuc if (__fb <= __vt && __vt < __fe) 25704684ddb6SLionel Sambuc __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; 25714684ddb6SLionel Sambuc __r = _VSTD::move(__fb, __fe, __r); 25724684ddb6SLionel Sambuc __n -= __bs; 25734684ddb6SLionel Sambuc __f += __bs; 25744684ddb6SLionel Sambuc } 25754684ddb6SLionel Sambuc return __r; 25764684ddb6SLionel Sambuc} 25774684ddb6SLionel Sambuc 25784684ddb6SLionel Sambuc// move assign [__f, __l) to [__r - (__l-__f), __r) backwards. 25794684ddb6SLionel Sambuc// If __vt points into [__f, __l), then add (__r - __l) to __vt. 25804684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 25814684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 25824684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, 25834684ddb6SLionel Sambuc const_pointer& __vt) 25844684ddb6SLionel Sambuc{ 25854684ddb6SLionel Sambuc // as if 25864684ddb6SLionel Sambuc // while (__f != __l) 25874684ddb6SLionel Sambuc // *--__r = _VSTD::move(*--__l); 25884684ddb6SLionel Sambuc difference_type __n = __l - __f; 25894684ddb6SLionel Sambuc while (__n > 0) 25904684ddb6SLionel Sambuc { 25914684ddb6SLionel Sambuc --__l; 25924684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 25934684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 25944684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 25954684ddb6SLionel Sambuc if (__bs > __n) 25964684ddb6SLionel Sambuc { 25974684ddb6SLionel Sambuc __bs = __n; 25984684ddb6SLionel Sambuc __lb = __le - __bs; 25994684ddb6SLionel Sambuc } 26004684ddb6SLionel Sambuc if (__lb <= __vt && __vt < __le) 26014684ddb6SLionel Sambuc __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; 26024684ddb6SLionel Sambuc __r = _VSTD::move_backward(__lb, __le, __r); 26034684ddb6SLionel Sambuc __n -= __bs; 26044684ddb6SLionel Sambuc __l -= __bs - 1; 26054684ddb6SLionel Sambuc } 26064684ddb6SLionel Sambuc return __r; 26074684ddb6SLionel Sambuc} 26084684ddb6SLionel Sambuc 26094684ddb6SLionel Sambuc// move construct [__f, __l) to [__r, __r + (__l-__f)). 26104684ddb6SLionel Sambuc// If __vt points into [__f, __l), then add (__r - __f) to __vt. 26114684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 26124684ddb6SLionel Sambucvoid 26134684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, 26144684ddb6SLionel Sambuc iterator __r, const_pointer& __vt) 26154684ddb6SLionel Sambuc{ 26164684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 26174684ddb6SLionel Sambuc // as if 26184684ddb6SLionel Sambuc // for (; __f != __l; ++__r, ++__f, ++__base::size()) 26194684ddb6SLionel Sambuc // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); 26204684ddb6SLionel Sambuc difference_type __n = __l - __f; 26214684ddb6SLionel Sambuc while (__n > 0) 26224684ddb6SLionel Sambuc { 26234684ddb6SLionel Sambuc pointer __fb = __f.__ptr_; 26244684ddb6SLionel Sambuc pointer __fe = *__f.__m_iter_ + __base::__block_size; 26254684ddb6SLionel Sambuc difference_type __bs = __fe - __fb; 26264684ddb6SLionel Sambuc if (__bs > __n) 26274684ddb6SLionel Sambuc { 26284684ddb6SLionel Sambuc __bs = __n; 26294684ddb6SLionel Sambuc __fe = __fb + __bs; 26304684ddb6SLionel Sambuc } 26314684ddb6SLionel Sambuc if (__fb <= __vt && __vt < __fe) 26324684ddb6SLionel Sambuc __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; 26334684ddb6SLionel Sambuc for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) 26344684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); 26354684ddb6SLionel Sambuc __n -= __bs; 26364684ddb6SLionel Sambuc __f += __bs; 26374684ddb6SLionel Sambuc } 26384684ddb6SLionel Sambuc} 26394684ddb6SLionel Sambuc 26404684ddb6SLionel Sambuc// move construct [__f, __l) to [__r - (__l-__f), __r) backwards. 26414684ddb6SLionel Sambuc// If __vt points into [__f, __l), then subtract (__l - __r) from __vt. 26424684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 26434684ddb6SLionel Sambucvoid 26444684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, 26454684ddb6SLionel Sambuc iterator __r, const_pointer& __vt) 26464684ddb6SLionel Sambuc{ 26474684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 26484684ddb6SLionel Sambuc // as if 26494684ddb6SLionel Sambuc // for (iterator __j = __l; __j != __f;) 26504684ddb6SLionel Sambuc // { 26514684ddb6SLionel Sambuc // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); 26524684ddb6SLionel Sambuc // --__base::__start_; 26534684ddb6SLionel Sambuc // ++__base::size(); 26544684ddb6SLionel Sambuc // } 26554684ddb6SLionel Sambuc difference_type __n = __l - __f; 26564684ddb6SLionel Sambuc while (__n > 0) 26574684ddb6SLionel Sambuc { 26584684ddb6SLionel Sambuc --__l; 26594684ddb6SLionel Sambuc pointer __lb = *__l.__m_iter_; 26604684ddb6SLionel Sambuc pointer __le = __l.__ptr_ + 1; 26614684ddb6SLionel Sambuc difference_type __bs = __le - __lb; 26624684ddb6SLionel Sambuc if (__bs > __n) 26634684ddb6SLionel Sambuc { 26644684ddb6SLionel Sambuc __bs = __n; 26654684ddb6SLionel Sambuc __lb = __le - __bs; 26664684ddb6SLionel Sambuc } 26674684ddb6SLionel Sambuc if (__lb <= __vt && __vt < __le) 26684684ddb6SLionel Sambuc __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; 26694684ddb6SLionel Sambuc while (__le != __lb) 26704684ddb6SLionel Sambuc { 26714684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); 26724684ddb6SLionel Sambuc --__base::__start_; 26734684ddb6SLionel Sambuc ++__base::size(); 26744684ddb6SLionel Sambuc } 26754684ddb6SLionel Sambuc __n -= __bs; 26764684ddb6SLionel Sambuc __l -= __bs - 1; 26774684ddb6SLionel Sambuc } 26784684ddb6SLionel Sambuc} 26794684ddb6SLionel Sambuc 26804684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 26814684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 26824684ddb6SLionel Sambucdeque<_Tp, _Allocator>::erase(const_iterator __f) 26834684ddb6SLionel Sambuc{ 26844684ddb6SLionel Sambuc iterator __b = __base::begin(); 26854684ddb6SLionel Sambuc difference_type __pos = __f - __b; 26864684ddb6SLionel Sambuc iterator __p = __b + __pos; 26874684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 2688*0a6a1f1dSLionel Sambuc if (__pos <= (__base::size() - 1) / 2) 26894684ddb6SLionel Sambuc { // erase from front 26904684ddb6SLionel Sambuc _VSTD::move_backward(__b, __p, _VSTD::next(__p)); 26914684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); 26924684ddb6SLionel Sambuc --__base::size(); 26934684ddb6SLionel Sambuc ++__base::__start_; 26944684ddb6SLionel Sambuc if (__front_spare() >= 2 * __base::__block_size) 26954684ddb6SLionel Sambuc { 26964684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); 26974684ddb6SLionel Sambuc __base::__map_.pop_front(); 26984684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size; 26994684ddb6SLionel Sambuc } 27004684ddb6SLionel Sambuc } 27014684ddb6SLionel Sambuc else 27024684ddb6SLionel Sambuc { // erase from back 27034684ddb6SLionel Sambuc iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); 27044684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 27054684ddb6SLionel Sambuc --__base::size(); 27064684ddb6SLionel Sambuc if (__back_spare() >= 2 * __base::__block_size) 27074684ddb6SLionel Sambuc { 27084684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 27094684ddb6SLionel Sambuc __base::__map_.pop_back(); 27104684ddb6SLionel Sambuc } 27114684ddb6SLionel Sambuc } 27124684ddb6SLionel Sambuc return __base::begin() + __pos; 27134684ddb6SLionel Sambuc} 27144684ddb6SLionel Sambuc 27154684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 27164684ddb6SLionel Sambuctypename deque<_Tp, _Allocator>::iterator 27174684ddb6SLionel Sambucdeque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) 27184684ddb6SLionel Sambuc{ 27194684ddb6SLionel Sambuc difference_type __n = __l - __f; 27204684ddb6SLionel Sambuc iterator __b = __base::begin(); 27214684ddb6SLionel Sambuc difference_type __pos = __f - __b; 27224684ddb6SLionel Sambuc iterator __p = __b + __pos; 27234684ddb6SLionel Sambuc if (__n > 0) 27244684ddb6SLionel Sambuc { 27254684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 2726*0a6a1f1dSLionel Sambuc if (__pos <= (__base::size() - __n) / 2) 27274684ddb6SLionel Sambuc { // erase from front 27284684ddb6SLionel Sambuc iterator __i = _VSTD::move_backward(__b, __p, __p + __n); 27294684ddb6SLionel Sambuc for (; __b != __i; ++__b) 27304684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); 27314684ddb6SLionel Sambuc __base::size() -= __n; 27324684ddb6SLionel Sambuc __base::__start_ += __n; 27334684ddb6SLionel Sambuc while (__front_spare() >= 2 * __base::__block_size) 27344684ddb6SLionel Sambuc { 27354684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); 27364684ddb6SLionel Sambuc __base::__map_.pop_front(); 27374684ddb6SLionel Sambuc __base::__start_ -= __base::__block_size; 27384684ddb6SLionel Sambuc } 27394684ddb6SLionel Sambuc } 27404684ddb6SLionel Sambuc else 27414684ddb6SLionel Sambuc { // erase from back 27424684ddb6SLionel Sambuc iterator __i = _VSTD::move(__p + __n, __base::end(), __p); 27434684ddb6SLionel Sambuc for (iterator __e = __base::end(); __i != __e; ++__i) 27444684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); 27454684ddb6SLionel Sambuc __base::size() -= __n; 27464684ddb6SLionel Sambuc while (__back_spare() >= 2 * __base::__block_size) 27474684ddb6SLionel Sambuc { 27484684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 27494684ddb6SLionel Sambuc __base::__map_.pop_back(); 27504684ddb6SLionel Sambuc } 27514684ddb6SLionel Sambuc } 27524684ddb6SLionel Sambuc } 27534684ddb6SLionel Sambuc return __base::begin() + __pos; 27544684ddb6SLionel Sambuc} 27554684ddb6SLionel Sambuc 27564684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 27574684ddb6SLionel Sambucvoid 27584684ddb6SLionel Sambucdeque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) 27594684ddb6SLionel Sambuc{ 27604684ddb6SLionel Sambuc iterator __e = __base::end(); 27614684ddb6SLionel Sambuc difference_type __n = __e - __f; 27624684ddb6SLionel Sambuc if (__n > 0) 27634684ddb6SLionel Sambuc { 27644684ddb6SLionel Sambuc allocator_type& __a = __base::__alloc(); 27654684ddb6SLionel Sambuc iterator __b = __base::begin(); 27664684ddb6SLionel Sambuc difference_type __pos = __f - __b; 27674684ddb6SLionel Sambuc for (iterator __p = __b + __pos; __p != __e; ++__p) 27684684ddb6SLionel Sambuc __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); 27694684ddb6SLionel Sambuc __base::size() -= __n; 27704684ddb6SLionel Sambuc while (__back_spare() >= 2 * __base::__block_size) 27714684ddb6SLionel Sambuc { 27724684ddb6SLionel Sambuc __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); 27734684ddb6SLionel Sambuc __base::__map_.pop_back(); 27744684ddb6SLionel Sambuc } 27754684ddb6SLionel Sambuc } 27764684ddb6SLionel Sambuc} 27774684ddb6SLionel Sambuc 27784684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 27794684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 27804684ddb6SLionel Sambucvoid 27814684ddb6SLionel Sambucdeque<_Tp, _Allocator>::swap(deque& __c) 2782*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 2783*0a6a1f1dSLionel Sambuc _NOEXCEPT 2784*0a6a1f1dSLionel Sambuc#else 27854684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 27864684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value) 2787*0a6a1f1dSLionel Sambuc#endif 27884684ddb6SLionel Sambuc{ 27894684ddb6SLionel Sambuc __base::swap(__c); 27904684ddb6SLionel Sambuc} 27914684ddb6SLionel Sambuc 27924684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 27934684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 27944684ddb6SLionel Sambucvoid 27954684ddb6SLionel Sambucdeque<_Tp, _Allocator>::clear() _NOEXCEPT 27964684ddb6SLionel Sambuc{ 27974684ddb6SLionel Sambuc __base::clear(); 27984684ddb6SLionel Sambuc} 27994684ddb6SLionel Sambuc 28004684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28014684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28024684ddb6SLionel Sambucbool 28034684ddb6SLionel Sambucoperator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28044684ddb6SLionel Sambuc{ 28054684ddb6SLionel Sambuc const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); 28064684ddb6SLionel Sambuc return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 28074684ddb6SLionel Sambuc} 28084684ddb6SLionel Sambuc 28094684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28104684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28114684ddb6SLionel Sambucbool 28124684ddb6SLionel Sambucoperator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28134684ddb6SLionel Sambuc{ 28144684ddb6SLionel Sambuc return !(__x == __y); 28154684ddb6SLionel Sambuc} 28164684ddb6SLionel Sambuc 28174684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28194684ddb6SLionel Sambucbool 28204684ddb6SLionel Sambucoperator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28214684ddb6SLionel Sambuc{ 28224684ddb6SLionel Sambuc return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 28234684ddb6SLionel Sambuc} 28244684ddb6SLionel Sambuc 28254684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28264684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28274684ddb6SLionel Sambucbool 28284684ddb6SLionel Sambucoperator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28294684ddb6SLionel Sambuc{ 28304684ddb6SLionel Sambuc return __y < __x; 28314684ddb6SLionel Sambuc} 28324684ddb6SLionel Sambuc 28334684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28354684ddb6SLionel Sambucbool 28364684ddb6SLionel Sambucoperator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28374684ddb6SLionel Sambuc{ 28384684ddb6SLionel Sambuc return !(__x < __y); 28394684ddb6SLionel Sambuc} 28404684ddb6SLionel Sambuc 28414684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28424684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28434684ddb6SLionel Sambucbool 28444684ddb6SLionel Sambucoperator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) 28454684ddb6SLionel Sambuc{ 28464684ddb6SLionel Sambuc return !(__y < __x); 28474684ddb6SLionel Sambuc} 28484684ddb6SLionel Sambuc 28494684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 28504684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28514684ddb6SLionel Sambucvoid 28524684ddb6SLionel Sambucswap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) 28534684ddb6SLionel Sambuc _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 28544684ddb6SLionel Sambuc{ 28554684ddb6SLionel Sambuc __x.swap(__y); 28564684ddb6SLionel Sambuc} 28574684ddb6SLionel Sambuc 28584684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 28594684ddb6SLionel Sambuc 28604684ddb6SLionel Sambuc#endif // _LIBCPP_DEQUE 2861