| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===---------------------------- deque -----------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
|  | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef _LIBCPP_DEQUE | 
|  | 12 | #define _LIBCPP_DEQUE | 
|  | 13 |  | 
|  | 14 | /* | 
|  | 15 | deque synopsis | 
|  | 16 |  | 
|  | 17 | namespace std | 
|  | 18 | { | 
|  | 19 |  | 
|  | 20 | template <class T, class Allocator = allocator<T> > | 
|  | 21 | class deque | 
|  | 22 | { | 
|  | 23 | public: | 
|  | 24 | // types: | 
|  | 25 | typedef T value_type; | 
|  | 26 | typedef Allocator allocator_type; | 
|  | 27 |  | 
|  | 28 | typedef typename allocator_type::reference reference; | 
|  | 29 | typedef typename allocator_type::const_reference const_reference; | 
|  | 30 | typedef implementation-defined iterator; | 
|  | 31 | typedef implementation-defined const_iterator; | 
|  | 32 | typedef typename allocator_type::size_type size_type; | 
|  | 33 | typedef typename allocator_type::difference_type difference_type; | 
|  | 34 |  | 
|  | 35 | typedef typename allocator_type::pointer pointer; | 
|  | 36 | typedef typename allocator_type::const_pointer const_pointer; | 
|  | 37 | typedef std::reverse_iterator<iterator> reverse_iterator; | 
|  | 38 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | 
|  | 39 |  | 
|  | 40 | // construct/copy/destroy: | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 41 | deque() noexcept(is_nothrow_default_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 42 | explicit deque(const allocator_type& a); | 
|  | 43 | explicit deque(size_type n); | 
| Marshall Clow | e00f53b | 2013-09-09 18:19:45 | [diff] [blame] | 44 | explicit deque(size_type n, const allocator_type& a); // C++14 | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 45 | deque(size_type n, const value_type& v); | 
|  | 46 | deque(size_type n, const value_type& v, const allocator_type& a); | 
|  | 47 | template <class InputIterator> | 
|  | 48 | deque(InputIterator f, InputIterator l); | 
|  | 49 | template <class InputIterator> | 
|  | 50 | deque(InputIterator f, InputIterator l, const allocator_type& a); | 
|  | 51 | deque(const deque& c); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 52 | deque(deque&& c) | 
|  | 53 | noexcept(is_nothrow_move_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 54 | deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); | 
|  | 55 | deque(const deque& c, const allocator_type& a); | 
|  | 56 | deque(deque&& c, const allocator_type& a); | 
|  | 57 | ~deque(); | 
|  | 58 |  | 
|  | 59 | deque& operator=(const deque& c); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 60 | deque& operator=(deque&& c) | 
|  | 61 | noexcept( | 
|  | 62 | allocator_type::propagate_on_container_move_assignment::value && | 
|  | 63 | is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 64 | deque& operator=(initializer_list<value_type> il); | 
|  | 65 |  | 
|  | 66 | template <class InputIterator> | 
|  | 67 | void assign(InputIterator f, InputIterator l); | 
|  | 68 | void assign(size_type n, const value_type& v); | 
|  | 69 | void assign(initializer_list<value_type> il); | 
|  | 70 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 71 | allocator_type get_allocator() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 72 |  | 
|  | 73 | // iterators: | 
|  | 74 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 75 | iterator begin() noexcept; | 
|  | 76 | const_iterator begin() const noexcept; | 
|  | 77 | iterator end() noexcept; | 
|  | 78 | const_iterator end() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 79 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 80 | reverse_iterator rbegin() noexcept; | 
|  | 81 | const_reverse_iterator rbegin() const noexcept; | 
|  | 82 | reverse_iterator rend() noexcept; | 
|  | 83 | const_reverse_iterator rend() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 84 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 85 | const_iterator cbegin() const noexcept; | 
|  | 86 | const_iterator cend() const noexcept; | 
|  | 87 | const_reverse_iterator crbegin() const noexcept; | 
|  | 88 | const_reverse_iterator crend() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 89 |  | 
|  | 90 | // capacity: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 91 | size_type size() const noexcept; | 
|  | 92 | size_type max_size() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 93 | void resize(size_type n); | 
|  | 94 | void resize(size_type n, const value_type& v); | 
|  | 95 | void shrink_to_fit(); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 96 | bool empty() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 97 |  | 
|  | 98 | // element access: | 
|  | 99 | reference operator[](size_type i); | 
|  | 100 | const_reference operator[](size_type i) const; | 
|  | 101 | reference at(size_type i); | 
|  | 102 | const_reference at(size_type i) const; | 
|  | 103 | reference front(); | 
|  | 104 | const_reference front() const; | 
|  | 105 | reference back(); | 
|  | 106 | const_reference back() const; | 
|  | 107 |  | 
|  | 108 | // modifiers: | 
|  | 109 | void push_front(const value_type& v); | 
|  | 110 | void push_front(value_type&& v); | 
|  | 111 | void push_back(const value_type& v); | 
|  | 112 | void push_back(value_type&& v); | 
|  | 113 | template <class... Args> void emplace_front(Args&&... args); | 
|  | 114 | template <class... Args> void emplace_back(Args&&... args); | 
|  | 115 | template <class... Args> iterator emplace(const_iterator p, Args&&... args); | 
|  | 116 | iterator insert(const_iterator p, const value_type& v); | 
|  | 117 | iterator insert(const_iterator p, value_type&& v); | 
|  | 118 | iterator insert(const_iterator p, size_type n, const value_type& v); | 
|  | 119 | template <class InputIterator> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 120 | iterator insert(const_iterator p, InputIterator f, InputIterator l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 121 | iterator insert(const_iterator p, initializer_list<value_type> il); | 
|  | 122 | void pop_front(); | 
|  | 123 | void pop_back(); | 
|  | 124 | iterator erase(const_iterator p); | 
|  | 125 | iterator erase(const_iterator f, const_iterator l); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 126 | void swap(deque& c) | 
|  | 127 | noexcept(!allocator_type::propagate_on_container_swap::value || | 
|  | 128 | __is_nothrow_swappable<allocator_type>::value); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 129 | void clear() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 130 | }; | 
|  | 131 |  | 
|  | 132 | template <class T, class Allocator> | 
|  | 133 | bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 134 | template <class T, class Allocator> | 
|  | 135 | bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 136 | template <class T, class Allocator> | 
|  | 137 | bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 138 | template <class T, class Allocator> | 
|  | 139 | bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 140 | template <class T, class Allocator> | 
|  | 141 | bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 142 | template <class T, class Allocator> | 
|  | 143 | bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
|  | 144 |  | 
|  | 145 | // specialized algorithms: | 
|  | 146 | template <class T, class Allocator> | 
| Howard Hinnant | c560727 | 2011-06-03 17:30:28 | [diff] [blame] | 147 | void swap(deque<T,Allocator>& x, deque<T,Allocator>& y) | 
|  | 148 | noexcept(noexcept(x.swap(y))); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 149 |  | 
|  | 150 | } // std | 
|  | 151 |  | 
|  | 152 | */ | 
|  | 153 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 154 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 155 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 156 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 157 |  | 
|  | 158 | #include <__config> | 
|  | 159 | #include <__split_buffer> | 
|  | 160 | #include <type_traits> | 
|  | 161 | #include <initializer_list> | 
|  | 162 | #include <iterator> | 
|  | 163 | #include <algorithm> | 
|  | 164 | #include <stdexcept> | 
|  | 165 |  | 
| Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 | [diff] [blame] | 166 | #include <__undef_min_max> | 
|  | 167 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 168 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 169 |  | 
|  | 170 | template <class _Tp, class _Allocator> class __deque_base; | 
|  | 171 |  | 
|  | 172 | template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, | 
|  | 173 | class _DiffType, _DiffType _BlockSize> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 174 | class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 175 |  | 
|  | 176 | template <class _RAIter, | 
|  | 177 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 178 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 179 | copy(_RAIter __f, | 
|  | 180 | _RAIter __l, | 
|  | 181 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 182 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
|  | 183 |  | 
|  | 184 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 185 | class _OutputIterator> | 
|  | 186 | _OutputIterator | 
|  | 187 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 188 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 189 | _OutputIterator __r); | 
|  | 190 |  | 
|  | 191 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 192 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 193 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 194 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 195 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 196 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 197 |  | 
|  | 198 | template <class _RAIter, | 
|  | 199 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 200 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 201 | copy_backward(_RAIter __f, | 
|  | 202 | _RAIter __l, | 
|  | 203 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 204 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
|  | 205 |  | 
|  | 206 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 207 | class _OutputIterator> | 
|  | 208 | _OutputIterator | 
|  | 209 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 210 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 211 | _OutputIterator __r); | 
|  | 212 |  | 
|  | 213 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 214 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 215 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 216 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 217 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 218 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 219 |  | 
|  | 220 | template <class _RAIter, | 
|  | 221 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 222 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 223 | move(_RAIter __f, | 
|  | 224 | _RAIter __l, | 
|  | 225 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 226 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
|  | 227 |  | 
|  | 228 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 229 | class _OutputIterator> | 
|  | 230 | _OutputIterator | 
|  | 231 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 232 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 233 | _OutputIterator __r); | 
|  | 234 |  | 
|  | 235 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 236 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 237 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 238 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 239 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 240 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 241 |  | 
|  | 242 | template <class _RAIter, | 
|  | 243 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 244 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 245 | move_backward(_RAIter __f, | 
|  | 246 | _RAIter __l, | 
|  | 247 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 248 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
|  | 249 |  | 
|  | 250 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 251 | class _OutputIterator> | 
|  | 252 | _OutputIterator | 
|  | 253 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 254 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 255 | _OutputIterator __r); | 
|  | 256 |  | 
|  | 257 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 258 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 259 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 260 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 261 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 262 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 263 |  | 
|  | 264 | template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, | 
|  | 265 | class _DiffType, _DiffType _BlockSize> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 266 | class _LIBCPP_TYPE_VIS_ONLY __deque_iterator | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 267 | { | 
|  | 268 | typedef _MapPointer __map_iterator; | 
|  | 269 | public: | 
|  | 270 | typedef _Pointer pointer; | 
|  | 271 | typedef _DiffType difference_type; | 
|  | 272 | private: | 
|  | 273 | __map_iterator __m_iter_; | 
|  | 274 | pointer __ptr_; | 
|  | 275 |  | 
|  | 276 | static const difference_type __block_size = _BlockSize; | 
|  | 277 | public: | 
|  | 278 | typedef _ValueType value_type; | 
|  | 279 | typedef random_access_iterator_tag iterator_category; | 
|  | 280 | typedef _Reference reference; | 
|  | 281 |  | 
| Marshall Clow | 5a11f94 | 2013-08-06 16:14:36 | [diff] [blame] | 282 | _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT | 
|  | 283 | #if _LIBCPP_STD_VER > 11 | 
|  | 284 | : __m_iter_(nullptr), __ptr_(nullptr) | 
|  | 285 | #endif | 
|  | 286 | {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 287 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 288 | template <class _Pp, class _Rp, class _MP> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 289 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 290 | __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it, | 
|  | 291 | typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 292 | : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} | 
|  | 293 |  | 
|  | 294 | _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} | 
|  | 295 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} | 
|  | 296 |  | 
|  | 297 | _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() | 
|  | 298 | { | 
|  | 299 | if (++__ptr_ - *__m_iter_ == __block_size) | 
|  | 300 | { | 
|  | 301 | ++__m_iter_; | 
|  | 302 | __ptr_ = *__m_iter_; | 
|  | 303 | } | 
|  | 304 | return *this; | 
|  | 305 | } | 
|  | 306 |  | 
|  | 307 | _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) | 
|  | 308 | { | 
|  | 309 | __deque_iterator __tmp = *this; | 
|  | 310 | ++(*this); | 
|  | 311 | return __tmp; | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() | 
|  | 315 | { | 
|  | 316 | if (__ptr_ == *__m_iter_) | 
|  | 317 | { | 
|  | 318 | --__m_iter_; | 
|  | 319 | __ptr_ = *__m_iter_ + __block_size; | 
|  | 320 | } | 
|  | 321 | --__ptr_; | 
|  | 322 | return *this; | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) | 
|  | 326 | { | 
|  | 327 | __deque_iterator __tmp = *this; | 
|  | 328 | --(*this); | 
|  | 329 | return __tmp; | 
|  | 330 | } | 
|  | 331 |  | 
|  | 332 | _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) | 
|  | 333 | { | 
|  | 334 | if (__n != 0) | 
|  | 335 | { | 
|  | 336 | __n += __ptr_ - *__m_iter_; | 
|  | 337 | if (__n > 0) | 
|  | 338 | { | 
|  | 339 | __m_iter_ += __n / __block_size; | 
|  | 340 | __ptr_ = *__m_iter_ + __n % __block_size; | 
|  | 341 | } | 
|  | 342 | else // (__n < 0) | 
|  | 343 | { | 
|  | 344 | difference_type __z = __block_size - 1 - __n; | 
|  | 345 | __m_iter_ -= __z / __block_size; | 
|  | 346 | __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); | 
|  | 347 | } | 
|  | 348 | } | 
|  | 349 | return *this; | 
|  | 350 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 351 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 352 | _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) | 
|  | 353 | { | 
|  | 354 | return *this += -__n; | 
|  | 355 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 356 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 357 | _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const | 
|  | 358 | { | 
|  | 359 | __deque_iterator __t(*this); | 
|  | 360 | __t += __n; | 
|  | 361 | return __t; | 
|  | 362 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 363 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 364 | _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const | 
|  | 365 | { | 
|  | 366 | __deque_iterator __t(*this); | 
|  | 367 | __t -= __n; | 
|  | 368 | return __t; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | _LIBCPP_INLINE_VISIBILITY | 
|  | 372 | friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) | 
|  | 373 | {return __it + __n;} | 
|  | 374 |  | 
|  | 375 | _LIBCPP_INLINE_VISIBILITY | 
|  | 376 | friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 377 | { | 
|  | 378 | if (__x != __y) | 
|  | 379 | return (__x.__m_iter_ - __y.__m_iter_) * __block_size | 
|  | 380 | + (__x.__ptr_ - *__x.__m_iter_) | 
|  | 381 | - (__y.__ptr_ - *__y.__m_iter_); | 
|  | 382 | return 0; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const | 
|  | 386 | {return *(*this + __n);} | 
|  | 387 |  | 
|  | 388 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 389 | bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 390 | {return __x.__ptr_ == __y.__ptr_;} | 
|  | 391 |  | 
|  | 392 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 393 | bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 394 | {return !(__x == __y);} | 
|  | 395 |  | 
|  | 396 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 397 | bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 398 | {return __x.__m_iter_ < __y.__m_iter_ || | 
|  | 399 | (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} | 
|  | 400 |  | 
|  | 401 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 402 | bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 403 | {return __y < __x;} | 
|  | 404 |  | 
|  | 405 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 406 | bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 407 | {return !(__y < __x);} | 
|  | 408 |  | 
|  | 409 | _LIBCPP_INLINE_VISIBILITY friend | 
|  | 410 | bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) | 
|  | 411 | {return !(__x < __y);} | 
|  | 412 |  | 
|  | 413 | private: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 414 | _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 415 | : __m_iter_(__m), __ptr_(__p) {} | 
|  | 416 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 417 | template <class _Tp, class _Ap> friend class __deque_base; | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 418 | template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 419 | template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 420 | friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 421 |  | 
|  | 422 | template <class _RAIter, | 
|  | 423 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 424 | friend | 
|  | 425 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 426 | copy(_RAIter __f, | 
|  | 427 | _RAIter __l, | 
|  | 428 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 429 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
|  | 430 |  | 
|  | 431 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 432 | class _OutputIterator> | 
|  | 433 | friend | 
|  | 434 | _OutputIterator | 
|  | 435 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 436 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 437 | _OutputIterator __r); | 
|  | 438 |  | 
|  | 439 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 440 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 441 | friend | 
|  | 442 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 443 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 444 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 445 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 446 |  | 
|  | 447 | template <class _RAIter, | 
|  | 448 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 449 | friend | 
|  | 450 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 451 | copy_backward(_RAIter __f, | 
|  | 452 | _RAIter __l, | 
|  | 453 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 454 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
|  | 455 |  | 
|  | 456 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 457 | class _OutputIterator> | 
|  | 458 | friend | 
|  | 459 | _OutputIterator | 
|  | 460 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 461 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 462 | _OutputIterator __r); | 
|  | 463 |  | 
|  | 464 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 465 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 466 | friend | 
|  | 467 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 468 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 469 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 470 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 471 |  | 
|  | 472 | template <class _RAIter, | 
|  | 473 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 474 | friend | 
|  | 475 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 476 | move(_RAIter __f, | 
|  | 477 | _RAIter __l, | 
|  | 478 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 479 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
|  | 480 |  | 
|  | 481 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 482 | class _OutputIterator> | 
|  | 483 | friend | 
|  | 484 | _OutputIterator | 
|  | 485 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 486 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 487 | _OutputIterator __r); | 
|  | 488 |  | 
|  | 489 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 490 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 491 | friend | 
|  | 492 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 493 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 494 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 495 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 496 |  | 
|  | 497 | template <class _RAIter, | 
|  | 498 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 499 | friend | 
|  | 500 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 501 | move_backward(_RAIter __f, | 
|  | 502 | _RAIter __l, | 
|  | 503 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 504 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
|  | 505 |  | 
|  | 506 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 507 | class _OutputIterator> | 
|  | 508 | friend | 
|  | 509 | _OutputIterator | 
|  | 510 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 511 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 512 | _OutputIterator __r); | 
|  | 513 |  | 
|  | 514 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 515 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 516 | friend | 
|  | 517 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 518 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 519 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 520 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
|  | 521 | }; | 
|  | 522 |  | 
|  | 523 | // copy | 
|  | 524 |  | 
|  | 525 | template <class _RAIter, | 
|  | 526 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 527 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 528 | copy(_RAIter __f, | 
|  | 529 | _RAIter __l, | 
|  | 530 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 531 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
|  | 532 | { | 
|  | 533 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
|  | 534 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
|  | 535 | while (__f != __l) | 
|  | 536 | { | 
|  | 537 | pointer __rb = __r.__ptr_; | 
|  | 538 | pointer __re = *__r.__m_iter_ + _B2; | 
|  | 539 | difference_type __bs = __re - __rb; | 
|  | 540 | difference_type __n = __l - __f; | 
|  | 541 | _RAIter __m = __l; | 
|  | 542 | if (__n > __bs) | 
|  | 543 | { | 
|  | 544 | __n = __bs; | 
|  | 545 | __m = __f + __n; | 
|  | 546 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 547 | _VSTD::copy(__f, __m, __rb); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 548 | __f = __m; | 
|  | 549 | __r += __n; | 
|  | 550 | } | 
|  | 551 | return __r; | 
|  | 552 | } | 
|  | 553 |  | 
|  | 554 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 555 | class _OutputIterator> | 
|  | 556 | _OutputIterator | 
|  | 557 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 558 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 559 | _OutputIterator __r) | 
|  | 560 | { | 
|  | 561 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 562 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 563 | difference_type __n = __l - __f; | 
|  | 564 | while (__n > 0) | 
|  | 565 | { | 
|  | 566 | pointer __fb = __f.__ptr_; | 
|  | 567 | pointer __fe = *__f.__m_iter_ + _B1; | 
|  | 568 | difference_type __bs = __fe - __fb; | 
|  | 569 | if (__bs > __n) | 
|  | 570 | { | 
|  | 571 | __bs = __n; | 
|  | 572 | __fe = __fb + __bs; | 
|  | 573 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 574 | __r = _VSTD::copy(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 575 | __n -= __bs; | 
|  | 576 | __f += __bs; | 
|  | 577 | } | 
|  | 578 | return __r; | 
|  | 579 | } | 
|  | 580 |  | 
|  | 581 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 582 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 583 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 584 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 585 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 586 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
|  | 587 | { | 
|  | 588 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 589 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 590 | difference_type __n = __l - __f; | 
|  | 591 | while (__n > 0) | 
|  | 592 | { | 
|  | 593 | pointer __fb = __f.__ptr_; | 
|  | 594 | pointer __fe = *__f.__m_iter_ + _B1; | 
|  | 595 | difference_type __bs = __fe - __fb; | 
|  | 596 | if (__bs > __n) | 
|  | 597 | { | 
|  | 598 | __bs = __n; | 
|  | 599 | __fe = __fb + __bs; | 
|  | 600 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 601 | __r = _VSTD::copy(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 602 | __n -= __bs; | 
|  | 603 | __f += __bs; | 
|  | 604 | } | 
|  | 605 | return __r; | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 | // copy_backward | 
|  | 609 |  | 
|  | 610 | template <class _RAIter, | 
|  | 611 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 612 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 613 | copy_backward(_RAIter __f, | 
|  | 614 | _RAIter __l, | 
|  | 615 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 616 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
|  | 617 | { | 
|  | 618 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
|  | 619 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
|  | 620 | while (__f != __l) | 
|  | 621 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 622 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 623 | pointer __rb = *__rp.__m_iter_; | 
|  | 624 | pointer __re = __rp.__ptr_ + 1; | 
|  | 625 | difference_type __bs = __re - __rb; | 
|  | 626 | difference_type __n = __l - __f; | 
|  | 627 | _RAIter __m = __f; | 
|  | 628 | if (__n > __bs) | 
|  | 629 | { | 
|  | 630 | __n = __bs; | 
|  | 631 | __m = __l - __n; | 
|  | 632 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 633 | _VSTD::copy_backward(__m, __l, __re); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 634 | __l = __m; | 
|  | 635 | __r -= __n; | 
|  | 636 | } | 
|  | 637 | return __r; | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 641 | class _OutputIterator> | 
|  | 642 | _OutputIterator | 
|  | 643 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 644 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 645 | _OutputIterator __r) | 
|  | 646 | { | 
|  | 647 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 648 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 649 | difference_type __n = __l - __f; | 
|  | 650 | while (__n > 0) | 
|  | 651 | { | 
|  | 652 | --__l; | 
|  | 653 | pointer __lb = *__l.__m_iter_; | 
|  | 654 | pointer __le = __l.__ptr_ + 1; | 
|  | 655 | difference_type __bs = __le - __lb; | 
|  | 656 | if (__bs > __n) | 
|  | 657 | { | 
|  | 658 | __bs = __n; | 
|  | 659 | __lb = __le - __bs; | 
|  | 660 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 661 | __r = _VSTD::copy_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 662 | __n -= __bs; | 
|  | 663 | __l -= __bs - 1; | 
|  | 664 | } | 
|  | 665 | return __r; | 
|  | 666 | } | 
|  | 667 |  | 
|  | 668 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 669 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 670 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 671 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 672 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 673 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
|  | 674 | { | 
|  | 675 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 676 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 677 | difference_type __n = __l - __f; | 
|  | 678 | while (__n > 0) | 
|  | 679 | { | 
|  | 680 | --__l; | 
|  | 681 | pointer __lb = *__l.__m_iter_; | 
|  | 682 | pointer __le = __l.__ptr_ + 1; | 
|  | 683 | difference_type __bs = __le - __lb; | 
|  | 684 | if (__bs > __n) | 
|  | 685 | { | 
|  | 686 | __bs = __n; | 
|  | 687 | __lb = __le - __bs; | 
|  | 688 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 689 | __r = _VSTD::copy_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 690 | __n -= __bs; | 
|  | 691 | __l -= __bs - 1; | 
|  | 692 | } | 
|  | 693 | return __r; | 
|  | 694 | } | 
|  | 695 |  | 
|  | 696 | // move | 
|  | 697 |  | 
|  | 698 | template <class _RAIter, | 
|  | 699 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 700 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 701 | move(_RAIter __f, | 
|  | 702 | _RAIter __l, | 
|  | 703 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 704 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
|  | 705 | { | 
|  | 706 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
|  | 707 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
|  | 708 | while (__f != __l) | 
|  | 709 | { | 
|  | 710 | pointer __rb = __r.__ptr_; | 
|  | 711 | pointer __re = *__r.__m_iter_ + _B2; | 
|  | 712 | difference_type __bs = __re - __rb; | 
|  | 713 | difference_type __n = __l - __f; | 
|  | 714 | _RAIter __m = __l; | 
|  | 715 | if (__n > __bs) | 
|  | 716 | { | 
|  | 717 | __n = __bs; | 
|  | 718 | __m = __f + __n; | 
|  | 719 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 720 | _VSTD::move(__f, __m, __rb); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 721 | __f = __m; | 
|  | 722 | __r += __n; | 
|  | 723 | } | 
|  | 724 | return __r; | 
|  | 725 | } | 
|  | 726 |  | 
|  | 727 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 728 | class _OutputIterator> | 
|  | 729 | _OutputIterator | 
|  | 730 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 731 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 732 | _OutputIterator __r) | 
|  | 733 | { | 
|  | 734 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 735 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 736 | difference_type __n = __l - __f; | 
|  | 737 | while (__n > 0) | 
|  | 738 | { | 
|  | 739 | pointer __fb = __f.__ptr_; | 
|  | 740 | pointer __fe = *__f.__m_iter_ + _B1; | 
|  | 741 | difference_type __bs = __fe - __fb; | 
|  | 742 | if (__bs > __n) | 
|  | 743 | { | 
|  | 744 | __bs = __n; | 
|  | 745 | __fe = __fb + __bs; | 
|  | 746 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 747 | __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 748 | __n -= __bs; | 
|  | 749 | __f += __bs; | 
|  | 750 | } | 
|  | 751 | return __r; | 
|  | 752 | } | 
|  | 753 |  | 
|  | 754 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 755 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 756 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 757 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 758 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 759 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
|  | 760 | { | 
|  | 761 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 762 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 763 | difference_type __n = __l - __f; | 
|  | 764 | while (__n > 0) | 
|  | 765 | { | 
|  | 766 | pointer __fb = __f.__ptr_; | 
|  | 767 | pointer __fe = *__f.__m_iter_ + _B1; | 
|  | 768 | difference_type __bs = __fe - __fb; | 
|  | 769 | if (__bs > __n) | 
|  | 770 | { | 
|  | 771 | __bs = __n; | 
|  | 772 | __fe = __fb + __bs; | 
|  | 773 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 774 | __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 775 | __n -= __bs; | 
|  | 776 | __f += __bs; | 
|  | 777 | } | 
|  | 778 | return __r; | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | // move_backward | 
|  | 782 |  | 
|  | 783 | template <class _RAIter, | 
|  | 784 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 785 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 786 | move_backward(_RAIter __f, | 
|  | 787 | _RAIter __l, | 
|  | 788 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
|  | 789 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
|  | 790 | { | 
|  | 791 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
|  | 792 | typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
|  | 793 | while (__f != __l) | 
|  | 794 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 795 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 796 | pointer __rb = *__rp.__m_iter_; | 
|  | 797 | pointer __re = __rp.__ptr_ + 1; | 
|  | 798 | difference_type __bs = __re - __rb; | 
|  | 799 | difference_type __n = __l - __f; | 
|  | 800 | _RAIter __m = __f; | 
|  | 801 | if (__n > __bs) | 
|  | 802 | { | 
|  | 803 | __n = __bs; | 
|  | 804 | __m = __l - __n; | 
|  | 805 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 806 | _VSTD::move_backward(__m, __l, __re); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 807 | __l = __m; | 
|  | 808 | __r -= __n; | 
|  | 809 | } | 
|  | 810 | return __r; | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 814 | class _OutputIterator> | 
|  | 815 | _OutputIterator | 
|  | 816 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 817 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 818 | _OutputIterator __r) | 
|  | 819 | { | 
|  | 820 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 821 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 822 | difference_type __n = __l - __f; | 
|  | 823 | while (__n > 0) | 
|  | 824 | { | 
|  | 825 | --__l; | 
|  | 826 | pointer __lb = *__l.__m_iter_; | 
|  | 827 | pointer __le = __l.__ptr_ + 1; | 
|  | 828 | difference_type __bs = __le - __lb; | 
|  | 829 | if (__bs > __n) | 
|  | 830 | { | 
|  | 831 | __bs = __n; | 
|  | 832 | __lb = __le - __bs; | 
|  | 833 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 834 | __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 835 | __n -= __bs; | 
|  | 836 | __l -= __bs - 1; | 
|  | 837 | } | 
|  | 838 | return __r; | 
|  | 839 | } | 
|  | 840 |  | 
|  | 841 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
|  | 842 | class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
|  | 843 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
|  | 844 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
|  | 845 | __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
|  | 846 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
|  | 847 | { | 
|  | 848 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
|  | 849 | typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
|  | 850 | difference_type __n = __l - __f; | 
|  | 851 | while (__n > 0) | 
|  | 852 | { | 
|  | 853 | --__l; | 
|  | 854 | pointer __lb = *__l.__m_iter_; | 
|  | 855 | pointer __le = __l.__ptr_ + 1; | 
|  | 856 | difference_type __bs = __le - __lb; | 
|  | 857 | if (__bs > __n) | 
|  | 858 | { | 
|  | 859 | __bs = __n; | 
|  | 860 | __lb = __le - __bs; | 
|  | 861 | } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 862 | __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 863 | __n -= __bs; | 
|  | 864 | __l -= __bs - 1; | 
|  | 865 | } | 
|  | 866 | return __r; | 
|  | 867 | } | 
|  | 868 |  | 
|  | 869 | template <bool> | 
|  | 870 | class __deque_base_common | 
|  | 871 | { | 
|  | 872 | protected: | 
|  | 873 | void __throw_length_error() const; | 
|  | 874 | void __throw_out_of_range() const; | 
|  | 875 | }; | 
|  | 876 |  | 
|  | 877 | template <bool __b> | 
|  | 878 | void | 
|  | 879 | __deque_base_common<__b>::__throw_length_error() const | 
|  | 880 | { | 
|  | 881 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 882 | throw length_error("deque"); | 
|  | 883 | #endif | 
|  | 884 | } | 
|  | 885 |  | 
|  | 886 | template <bool __b> | 
|  | 887 | void | 
|  | 888 | __deque_base_common<__b>::__throw_out_of_range() const | 
|  | 889 | { | 
|  | 890 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 891 | throw out_of_range("deque"); | 
|  | 892 | #endif | 
|  | 893 | } | 
|  | 894 |  | 
|  | 895 | template <class _Tp, class _Allocator> | 
|  | 896 | class __deque_base | 
|  | 897 | : protected __deque_base_common<true> | 
|  | 898 | { | 
|  | 899 | __deque_base(const __deque_base& __c); | 
|  | 900 | __deque_base& operator=(const __deque_base& __c); | 
|  | 901 | protected: | 
|  | 902 | typedef _Tp value_type; | 
|  | 903 | typedef _Allocator allocator_type; | 
|  | 904 | typedef allocator_traits<allocator_type> __alloc_traits; | 
|  | 905 | typedef value_type& reference; | 
|  | 906 | typedef const value_type& const_reference; | 
|  | 907 | typedef typename __alloc_traits::size_type size_type; | 
|  | 908 | typedef typename __alloc_traits::difference_type difference_type; | 
|  | 909 | typedef typename __alloc_traits::pointer pointer; | 
|  | 910 | typedef typename __alloc_traits::const_pointer const_pointer; | 
|  | 911 |  | 
|  | 912 | static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; | 
|  | 913 |  | 
|  | 914 | typedef typename __alloc_traits::template | 
|  | 915 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES | 
|  | 916 | rebind_alloc<pointer> | 
|  | 917 | #else | 
|  | 918 | rebind_alloc<pointer>::other | 
|  | 919 | #endif | 
|  | 920 | __pointer_allocator; | 
|  | 921 | typedef allocator_traits<__pointer_allocator> __map_traits; | 
|  | 922 | typedef typename __map_traits::pointer __map_pointer; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 923 | typedef typename __alloc_traits::template | 
|  | 924 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES | 
|  | 925 | rebind_alloc<const_pointer> | 
|  | 926 | #else | 
|  | 927 | rebind_alloc<const_pointer>::other | 
|  | 928 | #endif | 
|  | 929 | __const_pointer_allocator; | 
|  | 930 | typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 931 | typedef __split_buffer<pointer, __pointer_allocator> __map; | 
|  | 932 |  | 
|  | 933 | typedef __deque_iterator<value_type, pointer, reference, __map_pointer, | 
|  | 934 | difference_type, __block_size> iterator; | 
|  | 935 | typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, | 
|  | 936 | difference_type, __block_size> const_iterator; | 
|  | 937 |  | 
|  | 938 | __map __map_; | 
|  | 939 | size_type __start_; | 
|  | 940 | __compressed_pair<size_type, allocator_type> __size_; | 
|  | 941 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 942 | iterator begin() _NOEXCEPT; | 
|  | 943 | const_iterator begin() const _NOEXCEPT; | 
|  | 944 | iterator end() _NOEXCEPT; | 
|  | 945 | const_iterator end() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 946 |  | 
|  | 947 | _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 948 | _LIBCPP_INLINE_VISIBILITY | 
|  | 949 | const size_type& size() const _NOEXCEPT {return __size_.first();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 950 | _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 951 | _LIBCPP_INLINE_VISIBILITY | 
|  | 952 | const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 953 |  | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 954 | __deque_base() | 
|  | 955 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 956 | explicit __deque_base(const allocator_type& __a); | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 957 | public: | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 958 | ~__deque_base(); | 
|  | 959 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 960 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 961 |  | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 962 | __deque_base(__deque_base&& __c) | 
|  | 963 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 964 | __deque_base(__deque_base&& __c, const allocator_type& __a); | 
|  | 965 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 966 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 967 | void swap(__deque_base& __c) | 
| Howard Hinnant | b965fed | 2011-06-03 16:20:53 | [diff] [blame] | 968 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 969 | __is_nothrow_swappable<allocator_type>::value); | 
|  | 970 | protected: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 971 | void clear() _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 972 |  | 
|  | 973 | bool __invariants() const; | 
|  | 974 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 975 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 976 | void __move_assign(__deque_base& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 977 | _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
|  | 978 | is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 979 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 980 | __map_ = _VSTD::move(__c.__map_); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 981 | __start_ = __c.__start_; | 
|  | 982 | size() = __c.size(); | 
|  | 983 | __move_assign_alloc(__c); | 
|  | 984 | __c.__start_ = __c.size() = 0; | 
|  | 985 | } | 
|  | 986 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 987 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 988 | void __move_assign_alloc(__deque_base& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 989 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || | 
|  | 990 | is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 991 | {__move_assign_alloc(__c, integral_constant<bool, | 
|  | 992 | __alloc_traits::propagate_on_container_move_assignment::value>());} | 
|  | 993 |  | 
|  | 994 | private: | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 995 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 | [diff] [blame] | 996 | void __move_assign_alloc(__deque_base& __c, true_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 997 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 998 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 999 | __alloc() = _VSTD::move(__c.__alloc()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1000 | } | 
|  | 1001 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1002 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1003 | void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1004 | {} | 
|  | 1005 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1006 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1007 | static void __swap_alloc(allocator_type& __x, allocator_type& __y) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1008 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
|  | 1009 | __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1010 | {__swap_alloc(__x, __y, integral_constant<bool, | 
|  | 1011 | __alloc_traits::propagate_on_container_swap::value>());} | 
|  | 1012 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1013 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1014 | static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1015 | _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1016 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1017 | using _VSTD::swap; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1018 | swap(__x, __y); | 
|  | 1019 | } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1020 |  | 
|  | 1021 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1022 | static void __swap_alloc(allocator_type&, allocator_type&, false_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1023 | _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1024 | {} | 
|  | 1025 | }; | 
|  | 1026 |  | 
|  | 1027 | template <class _Tp, class _Allocator> | 
|  | 1028 | bool | 
|  | 1029 | __deque_base<_Tp, _Allocator>::__invariants() const | 
|  | 1030 | { | 
|  | 1031 | if (!__map_.__invariants()) | 
|  | 1032 | return false; | 
|  | 1033 | if (__map_.size() >= size_type(-1) / __block_size) | 
|  | 1034 | return false; | 
|  | 1035 | for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); | 
|  | 1036 | __i != __e; ++__i) | 
|  | 1037 | if (*__i == nullptr) | 
|  | 1038 | return false; | 
|  | 1039 | if (__map_.size() != 0) | 
|  | 1040 | { | 
|  | 1041 | if (size() >= __map_.size() * __block_size) | 
|  | 1042 | return false; | 
|  | 1043 | if (__start_ >= __map_.size() * __block_size - size()) | 
|  | 1044 | return false; | 
|  | 1045 | } | 
|  | 1046 | else | 
|  | 1047 | { | 
|  | 1048 | if (size() != 0) | 
|  | 1049 | return false; | 
|  | 1050 | if (__start_ != 0) | 
|  | 1051 | return false; | 
|  | 1052 | } | 
|  | 1053 | return true; | 
|  | 1054 | } | 
|  | 1055 |  | 
|  | 1056 | template <class _Tp, class _Allocator> | 
|  | 1057 | typename __deque_base<_Tp, _Allocator>::iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1058 | __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1059 | { | 
|  | 1060 | __map_pointer __mp = __map_.begin() + __start_ / __block_size; | 
|  | 1061 | return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | 
|  | 1062 | } | 
|  | 1063 |  | 
|  | 1064 | template <class _Tp, class _Allocator> | 
|  | 1065 | typename __deque_base<_Tp, _Allocator>::const_iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1066 | __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1067 | { | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1068 | __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1069 | return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | 
|  | 1070 | } | 
|  | 1071 |  | 
|  | 1072 | template <class _Tp, class _Allocator> | 
|  | 1073 | typename __deque_base<_Tp, _Allocator>::iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1074 | __deque_base<_Tp, _Allocator>::end() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1075 | { | 
|  | 1076 | size_type __p = size() + __start_; | 
|  | 1077 | __map_pointer __mp = __map_.begin() + __p / __block_size; | 
|  | 1078 | return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | 
|  | 1079 | } | 
|  | 1080 |  | 
|  | 1081 | template <class _Tp, class _Allocator> | 
|  | 1082 | typename __deque_base<_Tp, _Allocator>::const_iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1083 | __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1084 | { | 
|  | 1085 | size_type __p = size() + __start_; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1086 | __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1087 | return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | 
|  | 1088 | } | 
|  | 1089 |  | 
|  | 1090 | template <class _Tp, class _Allocator> | 
|  | 1091 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 1092 | __deque_base<_Tp, _Allocator>::__deque_base() | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 1093 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1094 | : __start_(0), __size_(0) {} | 
|  | 1095 |  | 
|  | 1096 | template <class _Tp, class _Allocator> | 
|  | 1097 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 1098 | __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) | 
|  | 1099 | : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} | 
|  | 1100 |  | 
|  | 1101 | template <class _Tp, class _Allocator> | 
|  | 1102 | __deque_base<_Tp, _Allocator>::~__deque_base() | 
|  | 1103 | { | 
|  | 1104 | clear(); | 
|  | 1105 | typename __map::iterator __i = __map_.begin(); | 
|  | 1106 | typename __map::iterator __e = __map_.end(); | 
|  | 1107 | for (; __i != __e; ++__i) | 
|  | 1108 | __alloc_traits::deallocate(__alloc(), *__i, __block_size); | 
|  | 1109 | } | 
|  | 1110 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1111 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1112 |  | 
|  | 1113 | template <class _Tp, class _Allocator> | 
|  | 1114 | __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1115 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1116 | : __map_(_VSTD::move(__c.__map_)), | 
|  | 1117 | __start_(_VSTD::move(__c.__start_)), | 
|  | 1118 | __size_(_VSTD::move(__c.__size_)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1119 | { | 
|  | 1120 | __c.__start_ = 0; | 
|  | 1121 | __c.size() = 0; | 
|  | 1122 | } | 
|  | 1123 |  | 
|  | 1124 | template <class _Tp, class _Allocator> | 
|  | 1125 | __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1126 | : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), | 
|  | 1127 | __start_(_VSTD::move(__c.__start_)), | 
|  | 1128 | __size_(_VSTD::move(__c.size()), __a) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1129 | { | 
|  | 1130 | if (__a == __c.__alloc()) | 
|  | 1131 | { | 
|  | 1132 | __c.__start_ = 0; | 
|  | 1133 | __c.size() = 0; | 
|  | 1134 | } | 
|  | 1135 | else | 
|  | 1136 | { | 
|  | 1137 | __map_.clear(); | 
|  | 1138 | __start_ = 0; | 
|  | 1139 | size() = 0; | 
|  | 1140 | } | 
|  | 1141 | } | 
|  | 1142 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1143 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1144 |  | 
|  | 1145 | template <class _Tp, class _Allocator> | 
|  | 1146 | void | 
|  | 1147 | __deque_base<_Tp, _Allocator>::swap(__deque_base& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1148 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| | 
|  | 1149 | __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1150 | { | 
|  | 1151 | __map_.swap(__c.__map_); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1152 | _VSTD::swap(__start_, __c.__start_); | 
|  | 1153 | _VSTD::swap(size(), __c.size()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1154 | __swap_alloc(__alloc(), __c.__alloc()); | 
|  | 1155 | } | 
|  | 1156 |  | 
|  | 1157 | template <class _Tp, class _Allocator> | 
|  | 1158 | void | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1159 | __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1160 | { | 
|  | 1161 | allocator_type& __a = __alloc(); | 
|  | 1162 | for (iterator __i = begin(), __e = end(); __i != __e; ++__i) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1163 | __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1164 | size() = 0; | 
|  | 1165 | while (__map_.size() > 2) | 
|  | 1166 | { | 
|  | 1167 | __alloc_traits::deallocate(__a, __map_.front(), __block_size); | 
|  | 1168 | __map_.pop_front(); | 
|  | 1169 | } | 
|  | 1170 | switch (__map_.size()) | 
|  | 1171 | { | 
|  | 1172 | case 1: | 
|  | 1173 | __start_ = __block_size / 2; | 
|  | 1174 | break; | 
|  | 1175 | case 2: | 
|  | 1176 | __start_ = __block_size; | 
|  | 1177 | break; | 
|  | 1178 | } | 
|  | 1179 | } | 
|  | 1180 |  | 
|  | 1181 | template <class _Tp, class _Allocator = allocator<_Tp> > | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 1182 | class _LIBCPP_TYPE_VIS_ONLY deque | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1183 | : private __deque_base<_Tp, _Allocator> | 
|  | 1184 | { | 
|  | 1185 | public: | 
|  | 1186 | // types: | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 1187 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1188 | typedef _Tp value_type; | 
|  | 1189 | typedef _Allocator allocator_type; | 
|  | 1190 |  | 
|  | 1191 | typedef __deque_base<value_type, allocator_type> __base; | 
|  | 1192 |  | 
|  | 1193 | typedef typename __base::__alloc_traits __alloc_traits; | 
|  | 1194 | typedef typename __base::reference reference; | 
|  | 1195 | typedef typename __base::const_reference const_reference; | 
|  | 1196 | typedef typename __base::iterator iterator; | 
|  | 1197 | typedef typename __base::const_iterator const_iterator; | 
|  | 1198 | typedef typename __base::size_type size_type; | 
|  | 1199 | typedef typename __base::difference_type difference_type; | 
|  | 1200 |  | 
|  | 1201 | typedef typename __base::pointer pointer; | 
|  | 1202 | typedef typename __base::const_pointer const_pointer; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1203 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; | 
|  | 1204 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1205 |  | 
|  | 1206 | // construct/copy/destroy: | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 1207 | _LIBCPP_INLINE_VISIBILITY | 
|  | 1208 | deque() | 
|  | 1209 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | 
|  | 1210 | {} | 
| Marshall Clow | 48c7470 | 2014-03-05 19:06:20 | [diff] [blame] | 1211 | _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1212 | explicit deque(size_type __n); | 
| Marshall Clow | ab04aad | 2013-09-07 16:16:19 | [diff] [blame] | 1213 | #if _LIBCPP_STD_VER > 11 | 
|  | 1214 | explicit deque(size_type __n, const _Allocator& __a); | 
|  | 1215 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1216 | deque(size_type __n, const value_type& __v); | 
|  | 1217 | deque(size_type __n, const value_type& __v, const allocator_type& __a); | 
|  | 1218 | template <class _InputIter> | 
|  | 1219 | deque(_InputIter __f, _InputIter __l, | 
|  | 1220 | typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); | 
|  | 1221 | template <class _InputIter> | 
|  | 1222 | deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 
|  | 1223 | typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); | 
|  | 1224 | deque(const deque& __c); | 
|  | 1225 | deque(const deque& __c, const allocator_type& __a); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1226 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1227 | deque(initializer_list<value_type> __il); | 
|  | 1228 | deque(initializer_list<value_type> __il, const allocator_type& __a); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1229 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1230 |  | 
|  | 1231 | deque& operator=(const deque& __c); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1232 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1233 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1234 | deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1235 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1236 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1237 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1238 | deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1239 | deque(deque&& __c, const allocator_type& __a); | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1240 | deque& operator=(deque&& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1241 | _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
|  | 1242 | is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1243 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1244 |  | 
|  | 1245 | template <class _InputIter> | 
|  | 1246 | void assign(_InputIter __f, _InputIter __l, | 
|  | 1247 | typename enable_if<__is_input_iterator<_InputIter>::value && | 
|  | 1248 | !__is_random_access_iterator<_InputIter>::value>::type* = 0); | 
|  | 1249 | template <class _RAIter> | 
|  | 1250 | void assign(_RAIter __f, _RAIter __l, | 
|  | 1251 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
|  | 1252 | void assign(size_type __n, const value_type& __v); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1253 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1254 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1255 | void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1256 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1257 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1258 | allocator_type get_allocator() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1259 |  | 
|  | 1260 | // iterators: | 
|  | 1261 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1262 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1263 | iterator begin() _NOEXCEPT {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1264 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1265 | const_iterator begin() const _NOEXCEPT {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1266 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1267 | iterator end() _NOEXCEPT {return __base::end();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1268 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1269 | const_iterator end() const _NOEXCEPT {return __base::end();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1270 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1271 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1272 | reverse_iterator rbegin() _NOEXCEPT | 
|  | 1273 | {return reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1274 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1275 | const_reverse_iterator rbegin() const _NOEXCEPT | 
|  | 1276 | {return const_reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1277 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1278 | reverse_iterator rend() _NOEXCEPT | 
|  | 1279 | {return reverse_iterator(__base::begin());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1280 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1281 | const_reverse_iterator rend() const _NOEXCEPT | 
|  | 1282 | {return const_reverse_iterator(__base::begin());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1283 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1284 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1285 | const_iterator cbegin() const _NOEXCEPT | 
|  | 1286 | {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1287 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1288 | const_iterator cend() const _NOEXCEPT | 
|  | 1289 | {return __base::end();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1290 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1291 | const_reverse_iterator crbegin() const _NOEXCEPT | 
|  | 1292 | {return const_reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1293 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1294 | const_reverse_iterator crend() const _NOEXCEPT | 
|  | 1295 | {return const_reverse_iterator(__base::begin());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1296 |  | 
|  | 1297 | // capacity: | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1298 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1299 | size_type size() const _NOEXCEPT {return __base::size();} | 
|  | 1300 | _LIBCPP_INLINE_VISIBILITY | 
|  | 1301 | size_type max_size() const _NOEXCEPT | 
|  | 1302 | {return __alloc_traits::max_size(__base::__alloc());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1303 | void resize(size_type __n); | 
|  | 1304 | void resize(size_type __n, const value_type& __v); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1305 | void shrink_to_fit() _NOEXCEPT; | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1306 | _LIBCPP_INLINE_VISIBILITY | 
|  | 1307 | bool empty() const _NOEXCEPT {return __base::size() == 0;} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1308 |  | 
|  | 1309 | // element access: | 
|  | 1310 | reference operator[](size_type __i); | 
|  | 1311 | const_reference operator[](size_type __i) const; | 
|  | 1312 | reference at(size_type __i); | 
|  | 1313 | const_reference at(size_type __i) const; | 
|  | 1314 | reference front(); | 
|  | 1315 | const_reference front() const; | 
|  | 1316 | reference back(); | 
|  | 1317 | const_reference back() const; | 
|  | 1318 |  | 
|  | 1319 | // 23.2.2.3 modifiers: | 
|  | 1320 | void push_front(const value_type& __v); | 
|  | 1321 | void push_back(const value_type& __v); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1322 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
|  | 1323 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1324 | template <class... _Args> void emplace_front(_Args&&... __args); | 
|  | 1325 | template <class... _Args> void emplace_back(_Args&&... __args); | 
|  | 1326 | template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1327 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1328 | void push_front(value_type&& __v); | 
|  | 1329 | void push_back(value_type&& __v); | 
|  | 1330 | iterator insert(const_iterator __p, value_type&& __v); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1331 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1332 | iterator insert(const_iterator __p, const value_type& __v); | 
|  | 1333 | iterator insert(const_iterator __p, size_type __n, const value_type& __v); | 
|  | 1334 | template <class _InputIter> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 1335 | iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1336 | typename enable_if<__is_input_iterator<_InputIter>::value | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 1337 | &&!__is_forward_iterator<_InputIter>::value>::type* = 0); | 
|  | 1338 | template <class _ForwardIterator> | 
|  | 1339 | iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 
|  | 1340 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value | 
|  | 1341 | &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1342 | template <class _BiIter> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 1343 | iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1344 | typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1345 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1347 | iterator insert(const_iterator __p, initializer_list<value_type> __il) | 
|  | 1348 | {return insert(__p, __il.begin(), __il.end());} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1349 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1350 | void pop_front(); | 
|  | 1351 | void pop_back(); | 
|  | 1352 | iterator erase(const_iterator __p); | 
|  | 1353 | iterator erase(const_iterator __f, const_iterator __l); | 
|  | 1354 |  | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1355 | void swap(deque& __c) | 
|  | 1356 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
|  | 1357 | __is_nothrow_swappable<allocator_type>::value); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1358 | void clear() _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1359 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1360 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1361 | bool __invariants() const {return __base::__invariants();} | 
|  | 1362 | private: | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1363 | typedef typename __base::__map_const_pointer __map_const_pointer; | 
|  | 1364 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1365 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1366 | static size_type __recommend_blocks(size_type __n) | 
|  | 1367 | { | 
|  | 1368 | return __n / __base::__block_size + (__n % __base::__block_size != 0); | 
|  | 1369 | } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1370 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1371 | size_type __capacity() const | 
|  | 1372 | { | 
|  | 1373 | return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; | 
|  | 1374 | } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1375 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1376 | size_type __front_spare() const | 
|  | 1377 | { | 
|  | 1378 | return __base::__start_; | 
|  | 1379 | } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1380 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1381 | size_type __back_spare() const | 
|  | 1382 | { | 
|  | 1383 | return __capacity() - (__base::__start_ + __base::size()); | 
|  | 1384 | } | 
|  | 1385 |  | 
|  | 1386 | template <class _InpIter> | 
|  | 1387 | void __append(_InpIter __f, _InpIter __l, | 
|  | 1388 | typename enable_if<__is_input_iterator<_InpIter>::value && | 
|  | 1389 | !__is_forward_iterator<_InpIter>::value>::type* = 0); | 
|  | 1390 | template <class _ForIter> | 
|  | 1391 | void __append(_ForIter __f, _ForIter __l, | 
|  | 1392 | typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); | 
|  | 1393 | void __append(size_type __n); | 
|  | 1394 | void __append(size_type __n, const value_type& __v); | 
|  | 1395 | void __erase_to_end(const_iterator __f); | 
|  | 1396 | void __add_front_capacity(); | 
|  | 1397 | void __add_front_capacity(size_type __n); | 
|  | 1398 | void __add_back_capacity(); | 
|  | 1399 | void __add_back_capacity(size_type __n); | 
|  | 1400 | iterator __move_and_check(iterator __f, iterator __l, iterator __r, | 
|  | 1401 | const_pointer& __vt); | 
|  | 1402 | iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, | 
|  | 1403 | const_pointer& __vt); | 
|  | 1404 | void __move_construct_and_check(iterator __f, iterator __l, | 
|  | 1405 | iterator __r, const_pointer& __vt); | 
|  | 1406 | void __move_construct_backward_and_check(iterator __f, iterator __l, | 
|  | 1407 | iterator __r, const_pointer& __vt); | 
|  | 1408 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1409 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1410 | void __copy_assign_alloc(const deque& __c) | 
|  | 1411 | {__copy_assign_alloc(__c, integral_constant<bool, | 
|  | 1412 | __alloc_traits::propagate_on_container_copy_assignment::value>());} | 
|  | 1413 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1414 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1415 | void __copy_assign_alloc(const deque& __c, true_type) | 
|  | 1416 | { | 
|  | 1417 | if (__base::__alloc() != __c.__alloc()) | 
|  | 1418 | { | 
|  | 1419 | clear(); | 
|  | 1420 | shrink_to_fit(); | 
|  | 1421 | } | 
|  | 1422 | __base::__alloc() = __c.__alloc(); | 
|  | 1423 | __base::__map_.__alloc() = __c.__map_.__alloc(); | 
|  | 1424 | } | 
|  | 1425 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1426 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1427 | void __copy_assign_alloc(const deque&, false_type) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1428 | {} | 
|  | 1429 |  | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1430 | void __move_assign(deque& __c, true_type) | 
|  | 1431 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1432 | void __move_assign(deque& __c, false_type); | 
|  | 1433 | }; | 
|  | 1434 |  | 
|  | 1435 | template <class _Tp, class _Allocator> | 
|  | 1436 | deque<_Tp, _Allocator>::deque(size_type __n) | 
|  | 1437 | { | 
|  | 1438 | if (__n > 0) | 
|  | 1439 | __append(__n); | 
|  | 1440 | } | 
|  | 1441 |  | 
| Marshall Clow | ab04aad | 2013-09-07 16:16:19 | [diff] [blame] | 1442 | #if _LIBCPP_STD_VER > 11 | 
|  | 1443 | template <class _Tp, class _Allocator> | 
|  | 1444 | deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) | 
|  | 1445 | : __base(__a) | 
|  | 1446 | { | 
|  | 1447 | if (__n > 0) | 
|  | 1448 | __append(__n); | 
|  | 1449 | } | 
|  | 1450 | #endif | 
|  | 1451 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1452 | template <class _Tp, class _Allocator> | 
|  | 1453 | deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) | 
|  | 1454 | { | 
|  | 1455 | if (__n > 0) | 
|  | 1456 | __append(__n, __v); | 
|  | 1457 | } | 
|  | 1458 |  | 
|  | 1459 | template <class _Tp, class _Allocator> | 
|  | 1460 | deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) | 
|  | 1461 | : __base(__a) | 
|  | 1462 | { | 
|  | 1463 | if (__n > 0) | 
|  | 1464 | __append(__n, __v); | 
|  | 1465 | } | 
|  | 1466 |  | 
|  | 1467 | template <class _Tp, class _Allocator> | 
|  | 1468 | template <class _InputIter> | 
|  | 1469 | deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, | 
|  | 1470 | typename enable_if<__is_input_iterator<_InputIter>::value>::type*) | 
|  | 1471 | { | 
|  | 1472 | __append(__f, __l); | 
|  | 1473 | } | 
|  | 1474 |  | 
|  | 1475 | template <class _Tp, class _Allocator> | 
|  | 1476 | template <class _InputIter> | 
|  | 1477 | deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 
|  | 1478 | typename enable_if<__is_input_iterator<_InputIter>::value>::type*) | 
|  | 1479 | : __base(__a) | 
|  | 1480 | { | 
|  | 1481 | __append(__f, __l); | 
|  | 1482 | } | 
|  | 1483 |  | 
|  | 1484 | template <class _Tp, class _Allocator> | 
|  | 1485 | deque<_Tp, _Allocator>::deque(const deque& __c) | 
|  | 1486 | : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) | 
|  | 1487 | { | 
|  | 1488 | __append(__c.begin(), __c.end()); | 
|  | 1489 | } | 
|  | 1490 |  | 
|  | 1491 | template <class _Tp, class _Allocator> | 
|  | 1492 | deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) | 
|  | 1493 | : __base(__a) | 
|  | 1494 | { | 
|  | 1495 | __append(__c.begin(), __c.end()); | 
|  | 1496 | } | 
|  | 1497 |  | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1498 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 1499 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1500 | template <class _Tp, class _Allocator> | 
|  | 1501 | deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) | 
|  | 1502 | { | 
|  | 1503 | __append(__il.begin(), __il.end()); | 
|  | 1504 | } | 
|  | 1505 |  | 
|  | 1506 | template <class _Tp, class _Allocator> | 
|  | 1507 | deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) | 
|  | 1508 | : __base(__a) | 
|  | 1509 | { | 
|  | 1510 | __append(__il.begin(), __il.end()); | 
|  | 1511 | } | 
|  | 1512 |  | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1513 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 1514 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1515 | template <class _Tp, class _Allocator> | 
|  | 1516 | deque<_Tp, _Allocator>& | 
|  | 1517 | deque<_Tp, _Allocator>::operator=(const deque& __c) | 
|  | 1518 | { | 
|  | 1519 | if (this != &__c) | 
|  | 1520 | { | 
|  | 1521 | __copy_assign_alloc(__c); | 
|  | 1522 | assign(__c.begin(), __c.end()); | 
|  | 1523 | } | 
|  | 1524 | return *this; | 
|  | 1525 | } | 
|  | 1526 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1527 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1528 |  | 
|  | 1529 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1530 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1531 | deque<_Tp, _Allocator>::deque(deque&& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1532 | _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1533 | : __base(_VSTD::move(__c)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1534 | { | 
|  | 1535 | } | 
|  | 1536 |  | 
|  | 1537 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1538 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1539 | deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1540 | : __base(_VSTD::move(__c), __a) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1541 | { | 
|  | 1542 | if (__a != __c.__alloc()) | 
|  | 1543 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 1544 | typedef move_iterator<iterator> _Ip; | 
|  | 1545 | assign(_Ip(__c.begin()), _Ip(__c.end())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1546 | } | 
|  | 1547 | } | 
|  | 1548 |  | 
|  | 1549 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1550 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1551 | deque<_Tp, _Allocator>& | 
|  | 1552 | deque<_Tp, _Allocator>::operator=(deque&& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1553 | _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
|  | 1554 | is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1555 | { | 
|  | 1556 | __move_assign(__c, integral_constant<bool, | 
|  | 1557 | __alloc_traits::propagate_on_container_move_assignment::value>()); | 
|  | 1558 | return *this; | 
|  | 1559 | } | 
|  | 1560 |  | 
|  | 1561 | template <class _Tp, class _Allocator> | 
|  | 1562 | void | 
|  | 1563 | deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) | 
|  | 1564 | { | 
|  | 1565 | if (__base::__alloc() != __c.__alloc()) | 
|  | 1566 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 1567 | typedef move_iterator<iterator> _Ip; | 
|  | 1568 | assign(_Ip(__c.begin()), _Ip(__c.end())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1569 | } | 
|  | 1570 | else | 
|  | 1571 | __move_assign(__c, true_type()); | 
|  | 1572 | } | 
|  | 1573 |  | 
|  | 1574 | template <class _Tp, class _Allocator> | 
|  | 1575 | void | 
|  | 1576 | deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1577 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1578 | { | 
|  | 1579 | clear(); | 
|  | 1580 | shrink_to_fit(); | 
|  | 1581 | __base::__move_assign(__c); | 
|  | 1582 | } | 
|  | 1583 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1584 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1585 |  | 
|  | 1586 | template <class _Tp, class _Allocator> | 
|  | 1587 | template <class _InputIter> | 
|  | 1588 | void | 
|  | 1589 | deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, | 
|  | 1590 | typename enable_if<__is_input_iterator<_InputIter>::value && | 
|  | 1591 | !__is_random_access_iterator<_InputIter>::value>::type*) | 
|  | 1592 | { | 
|  | 1593 | iterator __i = __base::begin(); | 
|  | 1594 | iterator __e = __base::end(); | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 1595 | for (; __f != __l && __i != __e; ++__f, (void) ++__i) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1596 | *__i = *__f; | 
|  | 1597 | if (__f != __l) | 
|  | 1598 | __append(__f, __l); | 
|  | 1599 | else | 
|  | 1600 | __erase_to_end(__i); | 
|  | 1601 | } | 
|  | 1602 |  | 
|  | 1603 | template <class _Tp, class _Allocator> | 
|  | 1604 | template <class _RAIter> | 
|  | 1605 | void | 
|  | 1606 | deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, | 
|  | 1607 | typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
|  | 1608 | { | 
|  | 1609 | if (static_cast<size_type>(__l - __f) > __base::size()) | 
|  | 1610 | { | 
|  | 1611 | _RAIter __m = __f + __base::size(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1612 | _VSTD::copy(__f, __m, __base::begin()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1613 | __append(__m, __l); | 
|  | 1614 | } | 
|  | 1615 | else | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1616 | __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1617 | } | 
|  | 1618 |  | 
|  | 1619 | template <class _Tp, class _Allocator> | 
|  | 1620 | void | 
|  | 1621 | deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) | 
|  | 1622 | { | 
|  | 1623 | if (__n > __base::size()) | 
|  | 1624 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1625 | _VSTD::fill_n(__base::begin(), __base::size(), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1626 | __n -= __base::size(); | 
|  | 1627 | __append(__n, __v); | 
|  | 1628 | } | 
|  | 1629 | else | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1630 | __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1631 | } | 
|  | 1632 |  | 
|  | 1633 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1634 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1635 | _Allocator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1636 | deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1637 | { | 
|  | 1638 | return __base::__alloc(); | 
|  | 1639 | } | 
|  | 1640 |  | 
|  | 1641 | template <class _Tp, class _Allocator> | 
|  | 1642 | void | 
|  | 1643 | deque<_Tp, _Allocator>::resize(size_type __n) | 
|  | 1644 | { | 
|  | 1645 | if (__n > __base::size()) | 
|  | 1646 | __append(__n - __base::size()); | 
|  | 1647 | else if (__n < __base::size()) | 
|  | 1648 | __erase_to_end(__base::begin() + __n); | 
|  | 1649 | } | 
|  | 1650 |  | 
|  | 1651 | template <class _Tp, class _Allocator> | 
|  | 1652 | void | 
|  | 1653 | deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) | 
|  | 1654 | { | 
|  | 1655 | if (__n > __base::size()) | 
|  | 1656 | __append(__n - __base::size(), __v); | 
|  | 1657 | else if (__n < __base::size()) | 
|  | 1658 | __erase_to_end(__base::begin() + __n); | 
|  | 1659 | } | 
|  | 1660 |  | 
|  | 1661 | template <class _Tp, class _Allocator> | 
|  | 1662 | void | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1663 | deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1664 | { | 
|  | 1665 | allocator_type& __a = __base::__alloc(); | 
|  | 1666 | if (empty()) | 
|  | 1667 | { | 
|  | 1668 | while (__base::__map_.size() > 0) | 
|  | 1669 | { | 
|  | 1670 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 1671 | __base::__map_.pop_back(); | 
|  | 1672 | } | 
|  | 1673 | __base::__start_ = 0; | 
|  | 1674 | } | 
|  | 1675 | else | 
|  | 1676 | { | 
|  | 1677 | if (__front_spare() >= __base::__block_size) | 
|  | 1678 | { | 
|  | 1679 | __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
|  | 1680 | __base::__map_.pop_front(); | 
|  | 1681 | __base::__start_ -= __base::__block_size; | 
|  | 1682 | } | 
|  | 1683 | if (__back_spare() >= __base::__block_size) | 
|  | 1684 | { | 
|  | 1685 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 1686 | __base::__map_.pop_back(); | 
|  | 1687 | } | 
|  | 1688 | } | 
|  | 1689 | __base::__map_.shrink_to_fit(); | 
|  | 1690 | } | 
|  | 1691 |  | 
|  | 1692 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1693 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1694 | typename deque<_Tp, _Allocator>::reference | 
|  | 1695 | deque<_Tp, _Allocator>::operator[](size_type __i) | 
|  | 1696 | { | 
|  | 1697 | size_type __p = __base::__start_ + __i; | 
|  | 1698 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1699 | } | 
|  | 1700 |  | 
|  | 1701 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1702 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1703 | typename deque<_Tp, _Allocator>::const_reference | 
|  | 1704 | deque<_Tp, _Allocator>::operator[](size_type __i) const | 
|  | 1705 | { | 
|  | 1706 | size_type __p = __base::__start_ + __i; | 
|  | 1707 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1708 | } | 
|  | 1709 |  | 
|  | 1710 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1711 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1712 | typename deque<_Tp, _Allocator>::reference | 
|  | 1713 | deque<_Tp, _Allocator>::at(size_type __i) | 
|  | 1714 | { | 
|  | 1715 | if (__i >= __base::size()) | 
|  | 1716 | __base::__throw_out_of_range(); | 
|  | 1717 | size_type __p = __base::__start_ + __i; | 
|  | 1718 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1719 | } | 
|  | 1720 |  | 
|  | 1721 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1722 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1723 | typename deque<_Tp, _Allocator>::const_reference | 
|  | 1724 | deque<_Tp, _Allocator>::at(size_type __i) const | 
|  | 1725 | { | 
|  | 1726 | if (__i >= __base::size()) | 
|  | 1727 | __base::__throw_out_of_range(); | 
|  | 1728 | size_type __p = __base::__start_ + __i; | 
|  | 1729 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1730 | } | 
|  | 1731 |  | 
|  | 1732 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1733 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1734 | typename deque<_Tp, _Allocator>::reference | 
|  | 1735 | deque<_Tp, _Allocator>::front() | 
|  | 1736 | { | 
|  | 1737 | return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 
|  | 1738 | + __base::__start_ % __base::__block_size); | 
|  | 1739 | } | 
|  | 1740 |  | 
|  | 1741 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1742 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1743 | typename deque<_Tp, _Allocator>::const_reference | 
|  | 1744 | deque<_Tp, _Allocator>::front() const | 
|  | 1745 | { | 
|  | 1746 | return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 
|  | 1747 | + __base::__start_ % __base::__block_size); | 
|  | 1748 | } | 
|  | 1749 |  | 
|  | 1750 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1751 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1752 | typename deque<_Tp, _Allocator>::reference | 
|  | 1753 | deque<_Tp, _Allocator>::back() | 
|  | 1754 | { | 
|  | 1755 | size_type __p = __base::size() + __base::__start_ - 1; | 
|  | 1756 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1757 | } | 
|  | 1758 |  | 
|  | 1759 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1760 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1761 | typename deque<_Tp, _Allocator>::const_reference | 
|  | 1762 | deque<_Tp, _Allocator>::back() const | 
|  | 1763 | { | 
|  | 1764 | size_type __p = __base::size() + __base::__start_ - 1; | 
|  | 1765 | return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
|  | 1766 | } | 
|  | 1767 |  | 
|  | 1768 | template <class _Tp, class _Allocator> | 
|  | 1769 | void | 
|  | 1770 | deque<_Tp, _Allocator>::push_back(const value_type& __v) | 
|  | 1771 | { | 
|  | 1772 | allocator_type& __a = __base::__alloc(); | 
|  | 1773 | if (__back_spare() == 0) | 
|  | 1774 | __add_back_capacity(); | 
|  | 1775 | // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1776 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1777 | ++__base::size(); | 
|  | 1778 | } | 
|  | 1779 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1780 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1781 |  | 
|  | 1782 | template <class _Tp, class _Allocator> | 
|  | 1783 | void | 
|  | 1784 | deque<_Tp, _Allocator>::push_back(value_type&& __v) | 
|  | 1785 | { | 
|  | 1786 | allocator_type& __a = __base::__alloc(); | 
|  | 1787 | if (__back_spare() == 0) | 
|  | 1788 | __add_back_capacity(); | 
|  | 1789 | // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1790 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1791 | ++__base::size(); | 
|  | 1792 | } | 
|  | 1793 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1794 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
|  | 1795 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1796 | template <class _Tp, class _Allocator> | 
|  | 1797 | template <class... _Args> | 
|  | 1798 | void | 
|  | 1799 | deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) | 
|  | 1800 | { | 
|  | 1801 | allocator_type& __a = __base::__alloc(); | 
|  | 1802 | if (__back_spare() == 0) | 
|  | 1803 | __add_back_capacity(); | 
|  | 1804 | // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1805 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1806 | ++__base::size(); | 
|  | 1807 | } | 
|  | 1808 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1809 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
|  | 1810 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1811 |  | 
|  | 1812 | template <class _Tp, class _Allocator> | 
|  | 1813 | void | 
|  | 1814 | deque<_Tp, _Allocator>::push_front(const value_type& __v) | 
|  | 1815 | { | 
|  | 1816 | allocator_type& __a = __base::__alloc(); | 
|  | 1817 | if (__front_spare() == 0) | 
|  | 1818 | __add_front_capacity(); | 
|  | 1819 | // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1820 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1821 | --__base::__start_; | 
|  | 1822 | ++__base::size(); | 
|  | 1823 | } | 
|  | 1824 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1825 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1826 |  | 
|  | 1827 | template <class _Tp, class _Allocator> | 
|  | 1828 | void | 
|  | 1829 | deque<_Tp, _Allocator>::push_front(value_type&& __v) | 
|  | 1830 | { | 
|  | 1831 | allocator_type& __a = __base::__alloc(); | 
|  | 1832 | if (__front_spare() == 0) | 
|  | 1833 | __add_front_capacity(); | 
|  | 1834 | // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1835 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1836 | --__base::__start_; | 
|  | 1837 | ++__base::size(); | 
|  | 1838 | } | 
|  | 1839 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1840 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
|  | 1841 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1842 | template <class _Tp, class _Allocator> | 
|  | 1843 | template <class... _Args> | 
|  | 1844 | void | 
|  | 1845 | deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) | 
|  | 1846 | { | 
|  | 1847 | allocator_type& __a = __base::__alloc(); | 
|  | 1848 | if (__front_spare() == 0) | 
|  | 1849 | __add_front_capacity(); | 
|  | 1850 | // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1851 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1852 | --__base::__start_; | 
|  | 1853 | ++__base::size(); | 
|  | 1854 | } | 
|  | 1855 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1856 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
|  | 1857 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1858 |  | 
|  | 1859 | template <class _Tp, class _Allocator> | 
|  | 1860 | typename deque<_Tp, _Allocator>::iterator | 
|  | 1861 | deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) | 
|  | 1862 | { | 
|  | 1863 | size_type __pos = __p - __base::begin(); | 
|  | 1864 | size_type __to_end = __base::size() - __pos; | 
|  | 1865 | allocator_type& __a = __base::__alloc(); | 
|  | 1866 | if (__pos < __to_end) | 
|  | 1867 | { // insert by shifting things backward | 
|  | 1868 | if (__front_spare() == 0) | 
|  | 1869 | __add_front_capacity(); | 
|  | 1870 | // __front_spare() >= 1 | 
|  | 1871 | if (__pos == 0) | 
|  | 1872 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1873 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1874 | --__base::__start_; | 
|  | 1875 | ++__base::size(); | 
|  | 1876 | } | 
|  | 1877 | else | 
|  | 1878 | { | 
|  | 1879 | const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
|  | 1880 | iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1881 | iterator __bm1 = _VSTD::prev(__b); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1882 | if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) | 
|  | 1883 | __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1884 | __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1885 | --__base::__start_; | 
|  | 1886 | ++__base::size(); | 
|  | 1887 | if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1888 | __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1889 | *__b = *__vt; | 
|  | 1890 | } | 
|  | 1891 | } | 
|  | 1892 | else | 
|  | 1893 | { // insert by shifting things forward | 
|  | 1894 | if (__back_spare() == 0) | 
|  | 1895 | __add_back_capacity(); | 
|  | 1896 | // __back_capacity >= 1 | 
|  | 1897 | size_type __de = __base::size() - __pos; | 
|  | 1898 | if (__de == 0) | 
|  | 1899 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1900 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1901 | ++__base::size(); | 
|  | 1902 | } | 
|  | 1903 | else | 
|  | 1904 | { | 
|  | 1905 | const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
|  | 1906 | iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1907 | iterator __em1 = _VSTD::prev(__e); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1908 | if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) | 
|  | 1909 | __vt = pointer_traits<const_pointer>::pointer_to(*__e); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1910 | __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1911 | ++__base::size(); | 
|  | 1912 | if (__de > 1) | 
|  | 1913 | __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); | 
|  | 1914 | *--__e = *__vt; | 
|  | 1915 | } | 
|  | 1916 | } | 
|  | 1917 | return __base::begin() + __pos; | 
|  | 1918 | } | 
|  | 1919 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1920 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1921 |  | 
|  | 1922 | template <class _Tp, class _Allocator> | 
|  | 1923 | typename deque<_Tp, _Allocator>::iterator | 
|  | 1924 | deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) | 
|  | 1925 | { | 
|  | 1926 | size_type __pos = __p - __base::begin(); | 
|  | 1927 | size_type __to_end = __base::size() - __pos; | 
|  | 1928 | allocator_type& __a = __base::__alloc(); | 
|  | 1929 | if (__pos < __to_end) | 
|  | 1930 | { // insert by shifting things backward | 
|  | 1931 | if (__front_spare() == 0) | 
|  | 1932 | __add_front_capacity(); | 
|  | 1933 | // __front_spare() >= 1 | 
|  | 1934 | if (__pos == 0) | 
|  | 1935 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1936 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1937 | --__base::__start_; | 
|  | 1938 | ++__base::size(); | 
|  | 1939 | } | 
|  | 1940 | else | 
|  | 1941 | { | 
|  | 1942 | iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1943 | iterator __bm1 = _VSTD::prev(__b); | 
|  | 1944 | __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1945 | --__base::__start_; | 
|  | 1946 | ++__base::size(); | 
|  | 1947 | if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1948 | __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 
|  | 1949 | *__b = _VSTD::move(__v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1950 | } | 
|  | 1951 | } | 
|  | 1952 | else | 
|  | 1953 | { // insert by shifting things forward | 
|  | 1954 | if (__back_spare() == 0) | 
|  | 1955 | __add_back_capacity(); | 
|  | 1956 | // __back_capacity >= 1 | 
|  | 1957 | size_type __de = __base::size() - __pos; | 
|  | 1958 | if (__de == 0) | 
|  | 1959 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1960 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1961 | ++__base::size(); | 
|  | 1962 | } | 
|  | 1963 | else | 
|  | 1964 | { | 
|  | 1965 | iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1966 | iterator __em1 = _VSTD::prev(__e); | 
|  | 1967 | __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1968 | ++__base::size(); | 
|  | 1969 | if (__de > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1970 | __e = _VSTD::move_backward(__e - __de, __em1, __e); | 
|  | 1971 | *--__e = _VSTD::move(__v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1972 | } | 
|  | 1973 | } | 
|  | 1974 | return __base::begin() + __pos; | 
|  | 1975 | } | 
|  | 1976 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1977 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
|  | 1978 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1979 | template <class _Tp, class _Allocator> | 
|  | 1980 | template <class... _Args> | 
|  | 1981 | typename deque<_Tp, _Allocator>::iterator | 
|  | 1982 | deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) | 
|  | 1983 | { | 
|  | 1984 | size_type __pos = __p - __base::begin(); | 
|  | 1985 | size_type __to_end = __base::size() - __pos; | 
|  | 1986 | allocator_type& __a = __base::__alloc(); | 
|  | 1987 | if (__pos < __to_end) | 
|  | 1988 | { // insert by shifting things backward | 
|  | 1989 | if (__front_spare() == 0) | 
|  | 1990 | __add_front_capacity(); | 
|  | 1991 | // __front_spare() >= 1 | 
|  | 1992 | if (__pos == 0) | 
|  | 1993 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1994 | __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1995 | --__base::__start_; | 
|  | 1996 | ++__base::size(); | 
|  | 1997 | } | 
|  | 1998 | else | 
|  | 1999 | { | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2000 | value_type __tmp(_VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2001 | iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2002 | iterator __bm1 = _VSTD::prev(__b); | 
|  | 2003 | __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2004 | --__base::__start_; | 
|  | 2005 | ++__base::size(); | 
|  | 2006 | if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2007 | __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2008 | *__b = _VSTD::move(__tmp); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2009 | } | 
|  | 2010 | } | 
|  | 2011 | else | 
|  | 2012 | { // insert by shifting things forward | 
|  | 2013 | if (__back_spare() == 0) | 
|  | 2014 | __add_back_capacity(); | 
|  | 2015 | // __back_capacity >= 1 | 
|  | 2016 | size_type __de = __base::size() - __pos; | 
|  | 2017 | if (__de == 0) | 
|  | 2018 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2019 | __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2020 | ++__base::size(); | 
|  | 2021 | } | 
|  | 2022 | else | 
|  | 2023 | { | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2024 | value_type __tmp(_VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2025 | iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2026 | iterator __em1 = _VSTD::prev(__e); | 
|  | 2027 | __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2028 | ++__base::size(); | 
|  | 2029 | if (__de > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2030 | __e = _VSTD::move_backward(__e - __de, __em1, __e); | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2031 | *--__e = _VSTD::move(__tmp); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2032 | } | 
|  | 2033 | } | 
|  | 2034 | return __base::begin() + __pos; | 
|  | 2035 | } | 
|  | 2036 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 2037 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
|  | 2038 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2039 |  | 
|  | 2040 | template <class _Tp, class _Allocator> | 
|  | 2041 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2042 | deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) | 
|  | 2043 | { | 
|  | 2044 | size_type __pos = __p - __base::begin(); | 
|  | 2045 | size_type __to_end = __base::size() - __pos; | 
|  | 2046 | allocator_type& __a = __base::__alloc(); | 
|  | 2047 | if (__pos < __to_end) | 
|  | 2048 | { // insert by shifting things backward | 
|  | 2049 | if (__n > __front_spare()) | 
|  | 2050 | __add_front_capacity(__n - __front_spare()); | 
|  | 2051 | // __n <= __front_spare() | 
|  | 2052 | size_type __old_n = __n; | 
|  | 2053 | iterator __old_begin = __base::begin(); | 
|  | 2054 | iterator __i = __old_begin; | 
|  | 2055 | if (__n > __pos) | 
|  | 2056 | { | 
|  | 2057 | for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2058 | __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2059 | __n = __pos; | 
|  | 2060 | } | 
|  | 2061 | if (__n > 0) | 
|  | 2062 | { | 
|  | 2063 | const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
|  | 2064 | iterator __obn = __old_begin + __n; | 
|  | 2065 | __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); | 
|  | 2066 | if (__n < __pos) | 
|  | 2067 | __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2068 | _VSTD::fill_n(__old_begin, __n, *__vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2069 | } | 
|  | 2070 | } | 
|  | 2071 | else | 
|  | 2072 | { // insert by shifting things forward | 
|  | 2073 | size_type __back_capacity = __back_spare(); | 
|  | 2074 | if (__n > __back_capacity) | 
|  | 2075 | __add_back_capacity(__n - __back_capacity); | 
|  | 2076 | // __n <= __back_capacity | 
|  | 2077 | size_type __old_n = __n; | 
|  | 2078 | iterator __old_end = __base::end(); | 
|  | 2079 | iterator __i = __old_end; | 
|  | 2080 | size_type __de = __base::size() - __pos; | 
|  | 2081 | if (__n > __de) | 
|  | 2082 | { | 
|  | 2083 | for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2084 | __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2085 | __n = __de; | 
|  | 2086 | } | 
|  | 2087 | if (__n > 0) | 
|  | 2088 | { | 
|  | 2089 | const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
|  | 2090 | iterator __oen = __old_end - __n; | 
|  | 2091 | __move_construct_and_check(__oen, __old_end, __i, __vt); | 
|  | 2092 | if (__n < __de) | 
|  | 2093 | __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2094 | _VSTD::fill_n(__old_end - __n, __n, *__vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2095 | } | 
|  | 2096 | } | 
|  | 2097 | return __base::begin() + __pos; | 
|  | 2098 | } | 
|  | 2099 |  | 
|  | 2100 | template <class _Tp, class _Allocator> | 
|  | 2101 | template <class _InputIter> | 
|  | 2102 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2103 | deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, | 
|  | 2104 | typename enable_if<__is_input_iterator<_InputIter>::value | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 2105 | &&!__is_forward_iterator<_InputIter>::value>::type*) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2106 | { | 
|  | 2107 | __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); | 
|  | 2108 | __buf.__construct_at_end(__f, __l); | 
|  | 2109 | typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; | 
|  | 2110 | return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); | 
|  | 2111 | } | 
|  | 2112 |  | 
|  | 2113 | template <class _Tp, class _Allocator> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame^] | 2114 | template <class _ForwardIterator> | 
|  | 2115 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2116 | deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 
|  | 2117 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value | 
|  | 2118 | &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*) | 
|  | 2119 | { | 
|  | 2120 | size_type __n = _VSTD::distance(__f, __l); | 
|  | 2121 | __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); | 
|  | 2122 | __buf.__construct_at_end(__f, __l); | 
|  | 2123 | typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; | 
|  | 2124 | return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); | 
|  | 2125 | } | 
|  | 2126 |  | 
|  | 2127 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2128 | template <class _BiIter> | 
|  | 2129 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2130 | deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, | 
|  | 2131 | typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) | 
|  | 2132 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2133 | size_type __n = _VSTD::distance(__f, __l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2134 | size_type __pos = __p - __base::begin(); | 
|  | 2135 | size_type __to_end = __base::size() - __pos; | 
|  | 2136 | allocator_type& __a = __base::__alloc(); | 
|  | 2137 | if (__pos < __to_end) | 
|  | 2138 | { // insert by shifting things backward | 
|  | 2139 | if (__n > __front_spare()) | 
|  | 2140 | __add_front_capacity(__n - __front_spare()); | 
|  | 2141 | // __n <= __front_spare() | 
|  | 2142 | size_type __old_n = __n; | 
|  | 2143 | iterator __old_begin = __base::begin(); | 
|  | 2144 | iterator __i = __old_begin; | 
|  | 2145 | _BiIter __m = __f; | 
|  | 2146 | if (__n > __pos) | 
|  | 2147 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2148 | __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2149 | for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2150 | __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2151 | __n = __pos; | 
|  | 2152 | } | 
|  | 2153 | if (__n > 0) | 
|  | 2154 | { | 
|  | 2155 | iterator __obn = __old_begin + __n; | 
|  | 2156 | for (iterator __j = __obn; __j != __old_begin;) | 
|  | 2157 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2158 | __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2159 | --__base::__start_; | 
|  | 2160 | ++__base::size(); | 
|  | 2161 | } | 
|  | 2162 | if (__n < __pos) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2163 | __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); | 
|  | 2164 | _VSTD::copy(__m, __l, __old_begin); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2165 | } | 
|  | 2166 | } | 
|  | 2167 | else | 
|  | 2168 | { // insert by shifting things forward | 
|  | 2169 | size_type __back_capacity = __back_spare(); | 
|  | 2170 | if (__n > __back_capacity) | 
|  | 2171 | __add_back_capacity(__n - __back_capacity); | 
|  | 2172 | // __n <= __back_capacity | 
|  | 2173 | size_type __old_n = __n; | 
|  | 2174 | iterator __old_end = __base::end(); | 
|  | 2175 | iterator __i = __old_end; | 
|  | 2176 | _BiIter __m = __l; | 
|  | 2177 | size_type __de = __base::size() - __pos; | 
|  | 2178 | if (__n > __de) | 
|  | 2179 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2180 | __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 2181 | for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2182 | __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2183 | __n = __de; | 
|  | 2184 | } | 
|  | 2185 | if (__n > 0) | 
|  | 2186 | { | 
|  | 2187 | iterator __oen = __old_end - __n; | 
|  | 2188 | for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2189 | __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2190 | if (__n < __de) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2191 | __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); | 
|  | 2192 | _VSTD::copy_backward(__f, __m, __old_end); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2193 | } | 
|  | 2194 | } | 
|  | 2195 | return __base::begin() + __pos; | 
|  | 2196 | } | 
|  | 2197 |  | 
|  | 2198 | template <class _Tp, class _Allocator> | 
|  | 2199 | template <class _InpIter> | 
|  | 2200 | void | 
|  | 2201 | deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, | 
|  | 2202 | typename enable_if<__is_input_iterator<_InpIter>::value && | 
|  | 2203 | !__is_forward_iterator<_InpIter>::value>::type*) | 
|  | 2204 | { | 
|  | 2205 | for (; __f != __l; ++__f) | 
|  | 2206 | push_back(*__f); | 
|  | 2207 | } | 
|  | 2208 |  | 
|  | 2209 | template <class _Tp, class _Allocator> | 
|  | 2210 | template <class _ForIter> | 
|  | 2211 | void | 
|  | 2212 | deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, | 
|  | 2213 | typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) | 
|  | 2214 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2215 | size_type __n = _VSTD::distance(__f, __l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2216 | allocator_type& __a = __base::__alloc(); | 
|  | 2217 | size_type __back_capacity = __back_spare(); | 
|  | 2218 | if (__n > __back_capacity) | 
|  | 2219 | __add_back_capacity(__n - __back_capacity); | 
|  | 2220 | // __n <= __back_capacity | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 2221 | for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2222 | __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2223 | } | 
|  | 2224 |  | 
|  | 2225 | template <class _Tp, class _Allocator> | 
|  | 2226 | void | 
|  | 2227 | deque<_Tp, _Allocator>::__append(size_type __n) | 
|  | 2228 | { | 
|  | 2229 | allocator_type& __a = __base::__alloc(); | 
|  | 2230 | size_type __back_capacity = __back_spare(); | 
|  | 2231 | if (__n > __back_capacity) | 
|  | 2232 | __add_back_capacity(__n - __back_capacity); | 
|  | 2233 | // __n <= __back_capacity | 
|  | 2234 | for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2235 | __alloc_traits::construct(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2236 | } | 
|  | 2237 |  | 
|  | 2238 | template <class _Tp, class _Allocator> | 
|  | 2239 | void | 
|  | 2240 | deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) | 
|  | 2241 | { | 
|  | 2242 | allocator_type& __a = __base::__alloc(); | 
|  | 2243 | size_type __back_capacity = __back_spare(); | 
|  | 2244 | if (__n > __back_capacity) | 
|  | 2245 | __add_back_capacity(__n - __back_capacity); | 
|  | 2246 | // __n <= __back_capacity | 
|  | 2247 | for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2248 | __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2249 | } | 
|  | 2250 |  | 
|  | 2251 | // Create front capacity for one block of elements. | 
|  | 2252 | // Strong guarantee. Either do it or don't touch anything. | 
|  | 2253 | template <class _Tp, class _Allocator> | 
|  | 2254 | void | 
|  | 2255 | deque<_Tp, _Allocator>::__add_front_capacity() | 
|  | 2256 | { | 
|  | 2257 | allocator_type& __a = __base::__alloc(); | 
|  | 2258 | if (__back_spare() >= __base::__block_size) | 
|  | 2259 | { | 
|  | 2260 | __base::__start_ += __base::__block_size; | 
|  | 2261 | pointer __pt = __base::__map_.back(); | 
|  | 2262 | __base::__map_.pop_back(); | 
|  | 2263 | __base::__map_.push_front(__pt); | 
|  | 2264 | } | 
|  | 2265 | // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer | 
|  | 2266 | else if (__base::__map_.size() < __base::__map_.capacity()) | 
|  | 2267 | { // we can put the new buffer into the map, but don't shift things around | 
|  | 2268 | // until all buffers are allocated. If we throw, we don't need to fix | 
|  | 2269 | // anything up (any added buffers are undetectible) | 
|  | 2270 | if (__base::__map_.__front_spare() > 0) | 
|  | 2271 | __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2272 | else | 
|  | 2273 | { | 
|  | 2274 | __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2275 | // Done allocating, reorder capacity | 
|  | 2276 | pointer __pt = __base::__map_.back(); | 
|  | 2277 | __base::__map_.pop_back(); | 
|  | 2278 | __base::__map_.push_front(__pt); | 
|  | 2279 | } | 
|  | 2280 | __base::__start_ = __base::__map_.size() == 1 ? | 
|  | 2281 | __base::__block_size / 2 : | 
|  | 2282 | __base::__start_ + __base::__block_size; | 
|  | 2283 | } | 
|  | 2284 | // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 
|  | 2285 | else | 
|  | 2286 | { | 
|  | 2287 | __split_buffer<pointer, typename __base::__pointer_allocator&> | 
|  | 2288 | __buf(max<size_type>(2 * __base::__map_.capacity(), 1), | 
|  | 2289 | 0, __base::__map_.__alloc()); | 
|  | 2290 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2291 | try | 
|  | 2292 | { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2293 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2294 | __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2295 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2296 | } | 
|  | 2297 | catch (...) | 
|  | 2298 | { | 
|  | 2299 | __alloc_traits::deallocate(__a, __buf.front(), __base::__block_size); | 
|  | 2300 | throw; | 
|  | 2301 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2302 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2303 | for (typename __base::__map_pointer __i = __base::__map_.begin(); | 
|  | 2304 | __i != __base::__map_.end(); ++__i) | 
|  | 2305 | __buf.push_back(*__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2306 | _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
|  | 2307 | _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
|  | 2308 | _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
|  | 2309 | _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2310 | __base::__start_ = __base::__map_.size() == 1 ? | 
|  | 2311 | __base::__block_size / 2 : | 
|  | 2312 | __base::__start_ + __base::__block_size; | 
|  | 2313 | } | 
|  | 2314 | } | 
|  | 2315 |  | 
|  | 2316 | // Create front capacity for __n elements. | 
|  | 2317 | // Strong guarantee. Either do it or don't touch anything. | 
|  | 2318 | template <class _Tp, class _Allocator> | 
|  | 2319 | void | 
|  | 2320 | deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) | 
|  | 2321 | { | 
|  | 2322 | allocator_type& __a = __base::__alloc(); | 
|  | 2323 | size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 
|  | 2324 | // Number of unused blocks at back: | 
|  | 2325 | size_type __back_capacity = __back_spare() / __base::__block_size; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2326 | __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2327 | __nb -= __back_capacity; // number of blocks need to allocate | 
|  | 2328 | // If __nb == 0, then we have sufficient capacity. | 
|  | 2329 | if (__nb == 0) | 
|  | 2330 | { | 
|  | 2331 | __base::__start_ += __base::__block_size * __back_capacity; | 
|  | 2332 | for (; __back_capacity > 0; --__back_capacity) | 
|  | 2333 | { | 
|  | 2334 | pointer __pt = __base::__map_.back(); | 
|  | 2335 | __base::__map_.pop_back(); | 
|  | 2336 | __base::__map_.push_front(__pt); | 
|  | 2337 | } | 
|  | 2338 | } | 
|  | 2339 | // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
|  | 2340 | else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 
|  | 2341 | { // we can put the new buffers into the map, but don't shift things around | 
|  | 2342 | // until all buffers are allocated. If we throw, we don't need to fix | 
|  | 2343 | // anything up (any added buffers are undetectible) | 
|  | 2344 | for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) | 
|  | 2345 | { | 
|  | 2346 | if (__base::__map_.__front_spare() == 0) | 
|  | 2347 | break; | 
|  | 2348 | __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2349 | } | 
|  | 2350 | for (; __nb > 0; --__nb, ++__back_capacity) | 
|  | 2351 | __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2352 | // Done allocating, reorder capacity | 
|  | 2353 | __base::__start_ += __back_capacity * __base::__block_size; | 
|  | 2354 | for (; __back_capacity > 0; --__back_capacity) | 
|  | 2355 | { | 
|  | 2356 | pointer __pt = __base::__map_.back(); | 
|  | 2357 | __base::__map_.pop_back(); | 
|  | 2358 | __base::__map_.push_front(__pt); | 
|  | 2359 | } | 
|  | 2360 | } | 
|  | 2361 | // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 
|  | 2362 | else | 
|  | 2363 | { | 
|  | 2364 | size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); | 
|  | 2365 | __split_buffer<pointer, typename __base::__pointer_allocator&> | 
|  | 2366 | __buf(max<size_type>(2* __base::__map_.capacity(), | 
|  | 2367 | __nb + __base::__map_.size()), | 
|  | 2368 | 0, __base::__map_.__alloc()); | 
|  | 2369 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2370 | try | 
|  | 2371 | { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2372 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2373 | for (; __nb > 0; --__nb) | 
|  | 2374 | __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2375 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2376 | } | 
|  | 2377 | catch (...) | 
|  | 2378 | { | 
|  | 2379 | for (typename __base::__map_pointer __i = __buf.begin(); | 
|  | 2380 | __i != __buf.end(); ++__i) | 
|  | 2381 | __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 
|  | 2382 | throw; | 
|  | 2383 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2384 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2385 | for (; __back_capacity > 0; --__back_capacity) | 
|  | 2386 | { | 
|  | 2387 | __buf.push_back(__base::__map_.back()); | 
|  | 2388 | __base::__map_.pop_back(); | 
|  | 2389 | } | 
|  | 2390 | for (typename __base::__map_pointer __i = __base::__map_.begin(); | 
|  | 2391 | __i != __base::__map_.end(); ++__i) | 
|  | 2392 | __buf.push_back(*__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2393 | _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
|  | 2394 | _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
|  | 2395 | _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
|  | 2396 | _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2397 | __base::__start_ += __ds; | 
|  | 2398 | } | 
|  | 2399 | } | 
|  | 2400 |  | 
|  | 2401 | // Create back capacity for one block of elements. | 
|  | 2402 | // Strong guarantee. Either do it or don't touch anything. | 
|  | 2403 | template <class _Tp, class _Allocator> | 
|  | 2404 | void | 
|  | 2405 | deque<_Tp, _Allocator>::__add_back_capacity() | 
|  | 2406 | { | 
|  | 2407 | allocator_type& __a = __base::__alloc(); | 
|  | 2408 | if (__front_spare() >= __base::__block_size) | 
|  | 2409 | { | 
|  | 2410 | __base::__start_ -= __base::__block_size; | 
|  | 2411 | pointer __pt = __base::__map_.front(); | 
|  | 2412 | __base::__map_.pop_front(); | 
|  | 2413 | __base::__map_.push_back(__pt); | 
|  | 2414 | } | 
|  | 2415 | // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
|  | 2416 | else if (__base::__map_.size() < __base::__map_.capacity()) | 
|  | 2417 | { // we can put the new buffer into the map, but don't shift things around | 
|  | 2418 | // until it is allocated. If we throw, we don't need to fix | 
|  | 2419 | // anything up (any added buffers are undetectible) | 
|  | 2420 | if (__base::__map_.__back_spare() != 0) | 
|  | 2421 | __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2422 | else | 
|  | 2423 | { | 
|  | 2424 | __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2425 | // Done allocating, reorder capacity | 
|  | 2426 | pointer __pt = __base::__map_.front(); | 
|  | 2427 | __base::__map_.pop_front(); | 
|  | 2428 | __base::__map_.push_back(__pt); | 
|  | 2429 | } | 
|  | 2430 | } | 
|  | 2431 | // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 
|  | 2432 | else | 
|  | 2433 | { | 
|  | 2434 | __split_buffer<pointer, typename __base::__pointer_allocator&> | 
|  | 2435 | __buf(max<size_type>(2* __base::__map_.capacity(), 1), | 
|  | 2436 | __base::__map_.size(), | 
|  | 2437 | __base::__map_.__alloc()); | 
|  | 2438 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2439 | try | 
|  | 2440 | { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2441 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2442 | __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2443 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2444 | } | 
|  | 2445 | catch (...) | 
|  | 2446 | { | 
|  | 2447 | __alloc_traits::deallocate(__a, __buf.back(), __base::__block_size); | 
|  | 2448 | throw; | 
|  | 2449 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2450 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2451 | for (typename __base::__map_pointer __i = __base::__map_.end(); | 
|  | 2452 | __i != __base::__map_.begin();) | 
|  | 2453 | __buf.push_front(*--__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2454 | _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
|  | 2455 | _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
|  | 2456 | _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
|  | 2457 | _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2458 | } | 
|  | 2459 | } | 
|  | 2460 |  | 
|  | 2461 | // Create back capacity for __n elements. | 
|  | 2462 | // Strong guarantee. Either do it or don't touch anything. | 
|  | 2463 | template <class _Tp, class _Allocator> | 
|  | 2464 | void | 
|  | 2465 | deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) | 
|  | 2466 | { | 
|  | 2467 | allocator_type& __a = __base::__alloc(); | 
|  | 2468 | size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 
|  | 2469 | // Number of unused blocks at front: | 
|  | 2470 | size_type __front_capacity = __front_spare() / __base::__block_size; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2471 | __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2472 | __nb -= __front_capacity; // number of blocks need to allocate | 
|  | 2473 | // If __nb == 0, then we have sufficient capacity. | 
|  | 2474 | if (__nb == 0) | 
|  | 2475 | { | 
|  | 2476 | __base::__start_ -= __base::__block_size * __front_capacity; | 
|  | 2477 | for (; __front_capacity > 0; --__front_capacity) | 
|  | 2478 | { | 
|  | 2479 | pointer __pt = __base::__map_.front(); | 
|  | 2480 | __base::__map_.pop_front(); | 
|  | 2481 | __base::__map_.push_back(__pt); | 
|  | 2482 | } | 
|  | 2483 | } | 
|  | 2484 | // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
|  | 2485 | else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 
|  | 2486 | { // we can put the new buffers into the map, but don't shift things around | 
|  | 2487 | // until all buffers are allocated. If we throw, we don't need to fix | 
|  | 2488 | // anything up (any added buffers are undetectible) | 
|  | 2489 | for (; __nb > 0; --__nb) | 
|  | 2490 | { | 
|  | 2491 | if (__base::__map_.__back_spare() == 0) | 
|  | 2492 | break; | 
|  | 2493 | __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2494 | } | 
|  | 2495 | for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += | 
|  | 2496 | __base::__block_size - (__base::__map_.size() == 1)) | 
|  | 2497 | __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2498 | // Done allocating, reorder capacity | 
|  | 2499 | __base::__start_ -= __base::__block_size * __front_capacity; | 
|  | 2500 | for (; __front_capacity > 0; --__front_capacity) | 
|  | 2501 | { | 
|  | 2502 | pointer __pt = __base::__map_.front(); | 
|  | 2503 | __base::__map_.pop_front(); | 
|  | 2504 | __base::__map_.push_back(__pt); | 
|  | 2505 | } | 
|  | 2506 | } | 
|  | 2507 | // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 
|  | 2508 | else | 
|  | 2509 | { | 
|  | 2510 | size_type __ds = __front_capacity * __base::__block_size; | 
|  | 2511 | __split_buffer<pointer, typename __base::__pointer_allocator&> | 
|  | 2512 | __buf(max<size_type>(2* __base::__map_.capacity(), | 
|  | 2513 | __nb + __base::__map_.size()), | 
|  | 2514 | __base::__map_.size() - __front_capacity, | 
|  | 2515 | __base::__map_.__alloc()); | 
|  | 2516 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2517 | try | 
|  | 2518 | { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2519 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2520 | for (; __nb > 0; --__nb) | 
|  | 2521 | __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
|  | 2522 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
|  | 2523 | } | 
|  | 2524 | catch (...) | 
|  | 2525 | { | 
|  | 2526 | for (typename __base::__map_pointer __i = __buf.begin(); | 
|  | 2527 | __i != __buf.end(); ++__i) | 
|  | 2528 | __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 
|  | 2529 | throw; | 
|  | 2530 | } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2531 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2532 | for (; __front_capacity > 0; --__front_capacity) | 
|  | 2533 | { | 
|  | 2534 | __buf.push_back(__base::__map_.front()); | 
|  | 2535 | __base::__map_.pop_front(); | 
|  | 2536 | } | 
|  | 2537 | for (typename __base::__map_pointer __i = __base::__map_.end(); | 
|  | 2538 | __i != __base::__map_.begin();) | 
|  | 2539 | __buf.push_front(*--__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2540 | _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
|  | 2541 | _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
|  | 2542 | _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
|  | 2543 | _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2544 | __base::__start_ -= __ds; | 
|  | 2545 | } | 
|  | 2546 | } | 
|  | 2547 |  | 
|  | 2548 | template <class _Tp, class _Allocator> | 
|  | 2549 | void | 
|  | 2550 | deque<_Tp, _Allocator>::pop_front() | 
|  | 2551 | { | 
|  | 2552 | allocator_type& __a = __base::__alloc(); | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2553 | __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + | 
|  | 2554 | __base::__start_ / __base::__block_size) + | 
|  | 2555 | __base::__start_ % __base::__block_size)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2556 | --__base::size(); | 
|  | 2557 | if (++__base::__start_ >= 2 * __base::__block_size) | 
|  | 2558 | { | 
|  | 2559 | __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
|  | 2560 | __base::__map_.pop_front(); | 
|  | 2561 | __base::__start_ -= __base::__block_size; | 
|  | 2562 | } | 
|  | 2563 | } | 
|  | 2564 |  | 
|  | 2565 | template <class _Tp, class _Allocator> | 
|  | 2566 | void | 
|  | 2567 | deque<_Tp, _Allocator>::pop_back() | 
|  | 2568 | { | 
|  | 2569 | allocator_type& __a = __base::__alloc(); | 
|  | 2570 | size_type __p = __base::size() + __base::__start_ - 1; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2571 | __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + | 
|  | 2572 | __p / __base::__block_size) + | 
|  | 2573 | __p % __base::__block_size)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2574 | --__base::size(); | 
|  | 2575 | if (__back_spare() >= 2 * __base::__block_size) | 
|  | 2576 | { | 
|  | 2577 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 2578 | __base::__map_.pop_back(); | 
|  | 2579 | } | 
|  | 2580 | } | 
|  | 2581 |  | 
|  | 2582 | // move assign [__f, __l) to [__r, __r + (__l-__f)). | 
|  | 2583 | // If __vt points into [__f, __l), then subtract (__f - __r) from __vt. | 
|  | 2584 | template <class _Tp, class _Allocator> | 
|  | 2585 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2586 | deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, | 
|  | 2587 | const_pointer& __vt) | 
|  | 2588 | { | 
|  | 2589 | // as if | 
|  | 2590 | // for (; __f != __l; ++__f, ++__r) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2591 | // *__r = _VSTD::move(*__f); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2592 | difference_type __n = __l - __f; | 
|  | 2593 | while (__n > 0) | 
|  | 2594 | { | 
|  | 2595 | pointer __fb = __f.__ptr_; | 
|  | 2596 | pointer __fe = *__f.__m_iter_ + __base::__block_size; | 
|  | 2597 | difference_type __bs = __fe - __fb; | 
|  | 2598 | if (__bs > __n) | 
|  | 2599 | { | 
|  | 2600 | __bs = __n; | 
|  | 2601 | __fe = __fb + __bs; | 
|  | 2602 | } | 
|  | 2603 | if (__fb <= __vt && __vt < __fe) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2604 | __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2605 | __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2606 | __n -= __bs; | 
|  | 2607 | __f += __bs; | 
|  | 2608 | } | 
|  | 2609 | return __r; | 
|  | 2610 | } | 
|  | 2611 |  | 
|  | 2612 | // move assign [__f, __l) to [__r - (__l-__f), __r) backwards. | 
|  | 2613 | // If __vt points into [__f, __l), then add (__r - __l) to __vt. | 
|  | 2614 | template <class _Tp, class _Allocator> | 
|  | 2615 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2616 | deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, | 
|  | 2617 | const_pointer& __vt) | 
|  | 2618 | { | 
|  | 2619 | // as if | 
|  | 2620 | // while (__f != __l) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2621 | // *--__r = _VSTD::move(*--__l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2622 | difference_type __n = __l - __f; | 
|  | 2623 | while (__n > 0) | 
|  | 2624 | { | 
|  | 2625 | --__l; | 
|  | 2626 | pointer __lb = *__l.__m_iter_; | 
|  | 2627 | pointer __le = __l.__ptr_ + 1; | 
|  | 2628 | difference_type __bs = __le - __lb; | 
|  | 2629 | if (__bs > __n) | 
|  | 2630 | { | 
|  | 2631 | __bs = __n; | 
|  | 2632 | __lb = __le - __bs; | 
|  | 2633 | } | 
|  | 2634 | if (__lb <= __vt && __vt < __le) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2635 | __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2636 | __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2637 | __n -= __bs; | 
|  | 2638 | __l -= __bs - 1; | 
|  | 2639 | } | 
|  | 2640 | return __r; | 
|  | 2641 | } | 
|  | 2642 |  | 
|  | 2643 | // move construct [__f, __l) to [__r, __r + (__l-__f)). | 
|  | 2644 | // If __vt points into [__f, __l), then add (__r - __f) to __vt. | 
|  | 2645 | template <class _Tp, class _Allocator> | 
|  | 2646 | void | 
|  | 2647 | deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, | 
|  | 2648 | iterator __r, const_pointer& __vt) | 
|  | 2649 | { | 
|  | 2650 | allocator_type& __a = __base::__alloc(); | 
|  | 2651 | // as if | 
|  | 2652 | // for (; __f != __l; ++__r, ++__f, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2653 | // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2654 | difference_type __n = __l - __f; | 
|  | 2655 | while (__n > 0) | 
|  | 2656 | { | 
|  | 2657 | pointer __fb = __f.__ptr_; | 
|  | 2658 | pointer __fe = *__f.__m_iter_ + __base::__block_size; | 
|  | 2659 | difference_type __bs = __fe - __fb; | 
|  | 2660 | if (__bs > __n) | 
|  | 2661 | { | 
|  | 2662 | __bs = __n; | 
|  | 2663 | __fe = __fb + __bs; | 
|  | 2664 | } | 
|  | 2665 | if (__fb <= __vt && __vt < __fe) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2666 | __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2667 | for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2668 | __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2669 | __n -= __bs; | 
|  | 2670 | __f += __bs; | 
|  | 2671 | } | 
|  | 2672 | } | 
|  | 2673 |  | 
|  | 2674 | // move construct [__f, __l) to [__r - (__l-__f), __r) backwards. | 
|  | 2675 | // If __vt points into [__f, __l), then subtract (__l - __r) from __vt. | 
|  | 2676 | template <class _Tp, class _Allocator> | 
|  | 2677 | void | 
|  | 2678 | deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, | 
|  | 2679 | iterator __r, const_pointer& __vt) | 
|  | 2680 | { | 
|  | 2681 | allocator_type& __a = __base::__alloc(); | 
|  | 2682 | // as if | 
|  | 2683 | // for (iterator __j = __l; __j != __f;) | 
|  | 2684 | // { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2685 | // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2686 | // --__base::__start_; | 
|  | 2687 | // ++__base::size(); | 
|  | 2688 | // } | 
|  | 2689 | difference_type __n = __l - __f; | 
|  | 2690 | while (__n > 0) | 
|  | 2691 | { | 
|  | 2692 | --__l; | 
|  | 2693 | pointer __lb = *__l.__m_iter_; | 
|  | 2694 | pointer __le = __l.__ptr_ + 1; | 
|  | 2695 | difference_type __bs = __le - __lb; | 
|  | 2696 | if (__bs > __n) | 
|  | 2697 | { | 
|  | 2698 | __bs = __n; | 
|  | 2699 | __lb = __le - __bs; | 
|  | 2700 | } | 
|  | 2701 | if (__lb <= __vt && __vt < __le) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2702 | __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2703 | while (__le != __lb) | 
|  | 2704 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2705 | __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2706 | --__base::__start_; | 
|  | 2707 | ++__base::size(); | 
|  | 2708 | } | 
|  | 2709 | __n -= __bs; | 
|  | 2710 | __l -= __bs - 1; | 
|  | 2711 | } | 
|  | 2712 | } | 
|  | 2713 |  | 
|  | 2714 | template <class _Tp, class _Allocator> | 
|  | 2715 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2716 | deque<_Tp, _Allocator>::erase(const_iterator __f) | 
|  | 2717 | { | 
|  | 2718 | difference_type __n = 1; | 
|  | 2719 | iterator __b = __base::begin(); | 
|  | 2720 | difference_type __pos = __f - __b; | 
|  | 2721 | iterator __p = __b + __pos; | 
|  | 2722 | allocator_type& __a = __base::__alloc(); | 
|  | 2723 | if (__pos < (__base::size() - 1) / 2) | 
|  | 2724 | { // erase from front | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2725 | _VSTD::move_backward(__b, __p, _VSTD::next(__p)); | 
|  | 2726 | __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2727 | --__base::size(); | 
|  | 2728 | ++__base::__start_; | 
|  | 2729 | if (__front_spare() >= 2 * __base::__block_size) | 
|  | 2730 | { | 
|  | 2731 | __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
|  | 2732 | __base::__map_.pop_front(); | 
|  | 2733 | __base::__start_ -= __base::__block_size; | 
|  | 2734 | } | 
|  | 2735 | } | 
|  | 2736 | else | 
|  | 2737 | { // erase from back | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2738 | iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); | 
|  | 2739 | __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2740 | --__base::size(); | 
|  | 2741 | if (__back_spare() >= 2 * __base::__block_size) | 
|  | 2742 | { | 
|  | 2743 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 2744 | __base::__map_.pop_back(); | 
|  | 2745 | } | 
|  | 2746 | } | 
|  | 2747 | return __base::begin() + __pos; | 
|  | 2748 | } | 
|  | 2749 |  | 
|  | 2750 | template <class _Tp, class _Allocator> | 
|  | 2751 | typename deque<_Tp, _Allocator>::iterator | 
|  | 2752 | deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) | 
|  | 2753 | { | 
|  | 2754 | difference_type __n = __l - __f; | 
|  | 2755 | iterator __b = __base::begin(); | 
|  | 2756 | difference_type __pos = __f - __b; | 
|  | 2757 | iterator __p = __b + __pos; | 
|  | 2758 | if (__n > 0) | 
|  | 2759 | { | 
|  | 2760 | allocator_type& __a = __base::__alloc(); | 
|  | 2761 | if (__pos < (__base::size() - __n) / 2) | 
|  | 2762 | { // erase from front | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2763 | iterator __i = _VSTD::move_backward(__b, __p, __p + __n); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2764 | for (; __b != __i; ++__b) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2765 | __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2766 | __base::size() -= __n; | 
|  | 2767 | __base::__start_ += __n; | 
|  | 2768 | while (__front_spare() >= 2 * __base::__block_size) | 
|  | 2769 | { | 
|  | 2770 | __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
|  | 2771 | __base::__map_.pop_front(); | 
|  | 2772 | __base::__start_ -= __base::__block_size; | 
|  | 2773 | } | 
|  | 2774 | } | 
|  | 2775 | else | 
|  | 2776 | { // erase from back | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2777 | iterator __i = _VSTD::move(__p + __n, __base::end(), __p); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2778 | for (iterator __e = __base::end(); __i != __e; ++__i) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2779 | __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2780 | __base::size() -= __n; | 
|  | 2781 | while (__back_spare() >= 2 * __base::__block_size) | 
|  | 2782 | { | 
|  | 2783 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 2784 | __base::__map_.pop_back(); | 
|  | 2785 | } | 
|  | 2786 | } | 
|  | 2787 | } | 
|  | 2788 | return __base::begin() + __pos; | 
|  | 2789 | } | 
|  | 2790 |  | 
|  | 2791 | template <class _Tp, class _Allocator> | 
|  | 2792 | void | 
|  | 2793 | deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) | 
|  | 2794 | { | 
|  | 2795 | iterator __e = __base::end(); | 
|  | 2796 | difference_type __n = __e - __f; | 
|  | 2797 | if (__n > 0) | 
|  | 2798 | { | 
|  | 2799 | allocator_type& __a = __base::__alloc(); | 
|  | 2800 | iterator __b = __base::begin(); | 
|  | 2801 | difference_type __pos = __f - __b; | 
|  | 2802 | for (iterator __p = __b + __pos; __p != __e; ++__p) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2803 | __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2804 | __base::size() -= __n; | 
|  | 2805 | while (__back_spare() >= 2 * __base::__block_size) | 
|  | 2806 | { | 
|  | 2807 | __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
|  | 2808 | __base::__map_.pop_back(); | 
|  | 2809 | } | 
|  | 2810 | } | 
|  | 2811 | } | 
|  | 2812 |  | 
|  | 2813 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 2814 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2815 | void | 
|  | 2816 | deque<_Tp, _Allocator>::swap(deque& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 2817 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
|  | 2818 | __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2819 | { | 
|  | 2820 | __base::swap(__c); | 
|  | 2821 | } | 
|  | 2822 |  | 
|  | 2823 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 2824 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2825 | void | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 2826 | deque<_Tp, _Allocator>::clear() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2827 | { | 
|  | 2828 | __base::clear(); | 
|  | 2829 | } | 
|  | 2830 |  | 
|  | 2831 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2832 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2833 | bool | 
|  | 2834 | operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2835 | { | 
|  | 2836 | const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2837 | return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2838 | } | 
|  | 2839 |  | 
|  | 2840 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2841 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2842 | bool | 
|  | 2843 | operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2844 | { | 
|  | 2845 | return !(__x == __y); | 
|  | 2846 | } | 
|  | 2847 |  | 
|  | 2848 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2849 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2850 | bool | 
|  | 2851 | operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2852 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2853 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2854 | } | 
|  | 2855 |  | 
|  | 2856 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2857 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2858 | bool | 
|  | 2859 | operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2860 | { | 
|  | 2861 | return __y < __x; | 
|  | 2862 | } | 
|  | 2863 |  | 
|  | 2864 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2865 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2866 | bool | 
|  | 2867 | operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2868 | { | 
|  | 2869 | return !(__x < __y); | 
|  | 2870 | } | 
|  | 2871 |  | 
|  | 2872 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2873 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2874 | bool | 
|  | 2875 | operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
|  | 2876 | { | 
|  | 2877 | return !(__y < __x); | 
|  | 2878 | } | 
|  | 2879 |  | 
|  | 2880 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2881 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2882 | void | 
|  | 2883 | swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 2884 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2885 | { | 
|  | 2886 | __x.swap(__y); | 
|  | 2887 | } | 
|  | 2888 |  | 
|  | 2889 | _LIBCPP_END_NAMESPACE_STD | 
|  | 2890 |  | 
|  | 2891 | #endif // _LIBCPP_DEQUE |