Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- list ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_LIST |
| 12 | #define _LIBCPP_LIST |
| 13 | |
| 14 | /* |
| 15 | list synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class T, class Alloc = allocator<T> > |
| 21 | class list |
| 22 | { |
| 23 | public: |
| 24 | |
| 25 | // types: |
| 26 | typedef T value_type; |
| 27 | typedef Alloc allocator_type; |
| 28 | typedef typename allocator_type::reference reference; |
| 29 | typedef typename allocator_type::const_reference const_reference; |
| 30 | typedef typename allocator_type::pointer pointer; |
| 31 | typedef typename allocator_type::const_pointer const_pointer; |
| 32 | typedef implementation-defined iterator; |
| 33 | typedef implementation-defined const_iterator; |
| 34 | typedef implementation-defined size_type; |
| 35 | typedef implementation-defined difference_type; |
| 36 | typedef reverse_iterator<iterator> reverse_iterator; |
| 37 | typedef reverse_iterator<const_iterator> const_reverse_iterator; |
| 38 | |
| 39 | list(); |
| 40 | explicit list(const allocator_type& a); |
| 41 | explicit list(size_type n); |
| 42 | list(size_type n, const value_type& value); |
| 43 | list(size_type n, const value_type& value, const allocator_type& a); |
| 44 | template <class Iter> |
| 45 | list(Iter first, Iter last); |
| 46 | template <class Iter> |
| 47 | list(Iter first, Iter last, const allocator_type& a); |
| 48 | list(const list& x); |
| 49 | list(const list&, const allocator_type& a); |
| 50 | list(list&& x); |
| 51 | list(list&&, const allocator_type& a); |
| 52 | list(initializer_list<value_type>); |
| 53 | list(initializer_list<value_type>, const allocator_type& a); |
| 54 | |
| 55 | ~list(); |
| 56 | |
| 57 | list& operator=(const list& x); |
| 58 | list& operator=(list&& x); |
| 59 | list& operator=(initializer_list<value_type>); |
| 60 | template <class Iter> |
| 61 | void assign(Iter first, Iter last); |
| 62 | void assign(size_type n, const value_type& t); |
| 63 | void assign(initializer_list<value_type>); |
| 64 | |
| 65 | allocator_type get_allocator() const; |
| 66 | |
| 67 | iterator begin(); |
| 68 | const_iterator begin() const; |
| 69 | iterator end(); |
| 70 | const_iterator end() const; |
| 71 | reverse_iterator rbegin(); |
| 72 | const_reverse_iterator rbegin() const; |
| 73 | reverse_iterator rend(); |
| 74 | const_reverse_iterator rend() const; |
| 75 | const_iterator cbegin() const; |
| 76 | const_iterator cend() const; |
| 77 | const_reverse_iterator crbegin() const; |
| 78 | const_reverse_iterator crend() const; |
| 79 | |
| 80 | reference front(); |
| 81 | const_reference front() const; |
| 82 | reference back(); |
| 83 | const_reference back() const; |
| 84 | |
| 85 | bool empty() const; |
| 86 | size_type size() const; |
| 87 | size_type max_size() const; |
| 88 | |
| 89 | template <class... Args> |
| 90 | void emplace_front(Args&&... args); |
| 91 | void pop_front(); |
| 92 | template <class... Args> |
| 93 | void emplace_back(Args&&... args); |
| 94 | void pop_back(); |
| 95 | void push_front(const value_type& x); |
| 96 | void push_front(value_type&& x); |
| 97 | void push_back(const value_type& x); |
| 98 | void push_back(value_type&& x); |
| 99 | template <class... Args> |
| 100 | iterator emplace(const_iterator position, Args&&... args); |
| 101 | iterator insert(const_iterator position, const value_type& x); |
| 102 | iterator insert(const_iterator position, value_type&& x); |
| 103 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 104 | template <class Iter> |
| 105 | iterator insert(const_iterator position, Iter first, Iter last); |
| 106 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 107 | |
| 108 | iterator erase(const_iterator position); |
| 109 | iterator erase(const_iterator position, const_iterator last); |
| 110 | |
| 111 | void resize(size_type sz); |
| 112 | void resize(size_type sz, const value_type& c); |
| 113 | |
| 114 | void swap(list<value_type,allocator_type>&); |
| 115 | void clear(); |
| 116 | |
| 117 | void splice(const_iterator position, list& x); |
| 118 | void splice(const_iterator position, list&& x); |
| 119 | void splice(const_iterator position, list& x, const_iterator i); |
| 120 | void splice(const_iterator position, list&& x, const_iterator i); |
| 121 | void splice(const_iterator position, list& x, const_iterator first, |
| 122 | const_iterator last); |
| 123 | void splice(const_iterator position, list&& x, const_iterator first, |
| 124 | const_iterator last); |
| 125 | |
| 126 | void remove(const value_type& value); |
| 127 | template <class Pred> void remove_if(Pred pred); |
| 128 | void unique(); |
| 129 | template <class BinaryPredicate> |
| 130 | void unique(BinaryPredicate binary_pred); |
| 131 | void merge(list& x); |
| 132 | void merge(list&& x); |
| 133 | template <class Compare> |
| 134 | void merge(list& x, Compare comp); |
| 135 | template <class Compare> |
| 136 | void merge(list&& x, Compare comp); |
| 137 | void sort(); |
| 138 | template <class Compare> |
| 139 | void sort(Compare comp); |
| 140 | void reverse(); |
| 141 | }; |
| 142 | |
| 143 | template <class T, class Alloc> |
| 144 | bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 145 | template <class T, class Alloc> |
| 146 | bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 147 | template <class T, class Alloc> |
| 148 | bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 149 | template <class T, class Alloc> |
| 150 | bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 151 | template <class T, class Alloc> |
| 152 | bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 153 | template <class T, class Alloc> |
| 154 | bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 155 | |
| 156 | template <class T, class Alloc> |
| 157 | void swap(list<T,Alloc>& x, list<T,Alloc>& y); |
| 158 | |
| 159 | } // std |
| 160 | |
| 161 | */ |
| 162 | |
| 163 | #include <__config> |
| 164 | |
| 165 | #include <memory> |
| 166 | #include <limits> |
| 167 | #include <initializer_list> |
| 168 | #include <iterator> |
| 169 | #include <algorithm> |
| 170 | |
| 171 | #pragma GCC system_header |
| 172 | |
| 173 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 174 | |
| 175 | template <class, class> struct __list_node; |
| 176 | |
| 177 | template <class _Tp, class _VoidPtr> |
| 178 | struct __list_node_base |
| 179 | { |
| 180 | typedef typename pointer_traits<_VoidPtr>::template |
| 181 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 182 | rebind<__list_node<_Tp, _VoidPtr> > pointer; |
| 183 | #else |
| 184 | rebind<__list_node<_Tp, _VoidPtr> >::other pointer; |
| 185 | #endif |
| 186 | |
| 187 | pointer __prev_; |
| 188 | pointer __next_; |
| 189 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | __list_node_base() |
| 192 | : __prev_(static_cast<pointer>(this)), |
| 193 | __next_(static_cast<pointer>(this)) |
| 194 | {} |
| 195 | }; |
| 196 | |
| 197 | template <class _Tp, class _VoidPtr> |
| 198 | struct __list_node |
| 199 | : public __list_node_base<_Tp, _VoidPtr> |
| 200 | { |
| 201 | _Tp __value_; |
| 202 | }; |
| 203 | |
| 204 | template <class, class> class list; |
| 205 | template <class, class> class __list_imp; |
| 206 | template <class, class> class __list_const_iterator; |
| 207 | |
| 208 | template <class _Tp, class _VoidPtr> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 209 | class _LIBCPP_VISIBLE __list_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 210 | { |
| 211 | typedef typename pointer_traits<_VoidPtr>::template |
| 212 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 213 | rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; |
| 214 | #else |
| 215 | rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; |
| 216 | #endif |
| 217 | |
| 218 | __node_pointer __ptr_; |
| 219 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 220 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 221 | explicit __list_iterator(__node_pointer __p) : __ptr_(__p) {} |
| 222 | |
| 223 | template<class, class> friend class list; |
| 224 | template<class, class> friend class __list_imp; |
| 225 | template<class, class> friend class __list_const_iterator; |
| 226 | public: |
| 227 | typedef bidirectional_iterator_tag iterator_category; |
| 228 | typedef _Tp value_type; |
| 229 | typedef value_type& reference; |
| 230 | typedef typename pointer_traits<_VoidPtr>::template |
| 231 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 232 | rebind<value_type> |
| 233 | #else |
| 234 | rebind<value_type>::other |
| 235 | #endif |
| 236 | pointer; |
| 237 | typedef typename pointer_traits<pointer>::difference_type difference_type; |
| 238 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | reference operator*() const {return __ptr_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 242 | pointer operator->() const {return &(operator*());} |
| 243 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | __list_iterator& operator++() {__ptr_ = __ptr_->__next_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 | __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} |
| 248 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 249 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | __list_iterator& operator--() {__ptr_ = __ptr_->__prev_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 251 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} |
| 253 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 254 | friend _LIBCPP_INLINE_VISIBILITY |
| 255 | bool operator==(const __list_iterator& __x, const __list_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | {return __x.__ptr_ == __y.__ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 257 | friend _LIBCPP_INLINE_VISIBILITY |
| 258 | bool operator!=(const __list_iterator& __x, const __list_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | {return !(__x == __y);} |
| 260 | }; |
| 261 | |
| 262 | template <class _Tp, class _VoidPtr> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 263 | class _LIBCPP_VISIBLE __list_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | { |
| 265 | typedef typename pointer_traits<_VoidPtr>::template |
| 266 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 267 | rebind<const __list_node<_Tp, _VoidPtr> > __node_pointer; |
| 268 | #else |
| 269 | rebind<const __list_node<_Tp, _VoidPtr> >::other __node_pointer; |
| 270 | #endif |
| 271 | |
| 272 | __node_pointer __ptr_; |
| 273 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 274 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | explicit __list_const_iterator(__node_pointer __p) : __ptr_(__p) {} |
| 276 | |
| 277 | template<class, class> friend class list; |
| 278 | template<class, class> friend class __list_imp; |
| 279 | public: |
| 280 | typedef bidirectional_iterator_tag iterator_category; |
| 281 | typedef _Tp value_type; |
| 282 | typedef const value_type& reference; |
| 283 | typedef typename pointer_traits<_VoidPtr>::template |
| 284 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 285 | rebind<const value_type> |
| 286 | #else |
| 287 | rebind<const value_type>::other |
| 288 | #endif |
| 289 | pointer; |
| 290 | typedef typename pointer_traits<pointer>::difference_type difference_type; |
| 291 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 292 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) : __ptr_(__p.__ptr_) {} |
| 294 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 295 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | reference operator*() const {return __ptr_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 297 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 298 | pointer operator->() const {return &(operator*());} |
| 299 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 300 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | __list_const_iterator& operator++() {__ptr_ = __ptr_->__next_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} |
| 304 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | __list_const_iterator& operator--() {__ptr_ = __ptr_->__prev_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 307 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} |
| 309 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 310 | friend _LIBCPP_INLINE_VISIBILITY |
| 311 | bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | {return __x.__ptr_ == __y.__ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 313 | friend _LIBCPP_INLINE_VISIBILITY |
| 314 | bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | {return !(__x == __y);} |
| 316 | }; |
| 317 | |
| 318 | template <class _Tp, class _Alloc> |
| 319 | class __list_imp |
| 320 | { |
| 321 | __list_imp(const __list_imp&); |
| 322 | __list_imp& operator=(const __list_imp&); |
| 323 | protected: |
| 324 | typedef _Tp value_type; |
| 325 | typedef _Alloc allocator_type; |
| 326 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 327 | typedef typename __alloc_traits::size_type size_type; |
| 328 | typedef typename __alloc_traits::void_pointer __void_pointer; |
| 329 | typedef __list_iterator<value_type, __void_pointer> iterator; |
| 330 | typedef __list_const_iterator<value_type, __void_pointer> const_iterator; |
| 331 | typedef __list_node_base<value_type, __void_pointer> __node_base; |
| 332 | typedef __list_node<value_type, __void_pointer> __node; |
| 333 | typedef typename __alloc_traits::template |
| 334 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 335 | rebind_alloc<__node> |
| 336 | #else |
| 337 | rebind_alloc<__node>::other |
| 338 | #endif |
| 339 | __node_allocator; |
| 340 | typedef allocator_traits<__node_allocator> __node_alloc_traits; |
| 341 | typedef typename __node_alloc_traits::pointer __node_pointer; |
| 342 | typedef typename __node_alloc_traits::const_pointer __node_const_pointer; |
| 343 | typedef typename __alloc_traits::pointer pointer; |
| 344 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 345 | typedef typename __alloc_traits::difference_type difference_type; |
| 346 | |
| 347 | __node_base __end_; |
| 348 | __compressed_pair<size_type, __node_allocator> __size_alloc_; |
| 349 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 351 | size_type& __sz() {return __size_alloc_.first();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 352 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | const size_type& __sz() const {return __size_alloc_.first();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 354 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | __node_allocator& __node_alloc() {return __size_alloc_.second();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 | const __node_allocator& __node_alloc() const {return __size_alloc_.second();} |
| 358 | |
| 359 | static void __unlink_nodes(__node_base& __f, __node_base& __l); |
| 360 | |
| 361 | __list_imp(); |
| 362 | __list_imp(const allocator_type& __a); |
| 363 | ~__list_imp(); |
| 364 | void clear(); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 365 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | bool empty() const {return __sz() == 0;} |
| 367 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 368 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | iterator begin() {return iterator(__end_.__next_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | const_iterator begin() const {return const_iterator(__end_.__next_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 372 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | iterator end() {return iterator(static_cast<__node_pointer> (&__end_));} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 374 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | const_iterator end() const {return const_iterator(static_cast<__node_const_pointer>(&__end_));} |
| 376 | |
| 377 | void swap(__list_imp& __c); |
| 378 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 379 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 380 | void __copy_assign_alloc(const __list_imp& __c) |
| 381 | {__copy_assign_alloc(__c, integral_constant<bool, |
| 382 | __node_alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 383 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 384 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | void __move_assign_alloc(__list_imp& __c) |
| 386 | {__move_assign_alloc(__c, integral_constant<bool, |
| 387 | __node_alloc_traits::propagate_on_container_move_assignment::value>());} |
| 388 | |
| 389 | private: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) |
| 392 | {__swap_alloc(__x, __y, integral_constant<bool, |
| 393 | __node_alloc_traits::propagate_on_container_swap::value>());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type) |
| 396 | { |
| 397 | using _STD::swap; |
| 398 | swap(__x, __y); |
| 399 | } |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type) |
| 402 | {} |
| 403 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 405 | void __copy_assign_alloc(const __list_imp& __c, true_type) |
| 406 | { |
| 407 | if (__node_alloc() != __c.__node_alloc()) |
| 408 | clear(); |
| 409 | __node_alloc() = __c.__node_alloc(); |
| 410 | } |
| 411 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | void __copy_assign_alloc(const __list_imp& __c, false_type) |
| 414 | {} |
| 415 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 416 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 417 | void __move_assign_alloc(const __list_imp& __c, true_type) |
| 418 | { |
| 419 | __node_alloc() = _STD::move(__c.__node_alloc()); |
| 420 | } |
| 421 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 422 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | void __move_assign_alloc(const __list_imp& __c, false_type) |
| 424 | {} |
| 425 | }; |
| 426 | |
| 427 | // Unlink nodes [__f, __l] |
| 428 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 429 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 430 | void |
| 431 | __list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l) |
| 432 | { |
| 433 | __f.__prev_->__next_ = __l.__next_; |
| 434 | __l.__next_->__prev_ = __f.__prev_; |
| 435 | } |
| 436 | |
| 437 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 438 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | __list_imp<_Tp, _Alloc>::__list_imp() |
| 440 | : __size_alloc_(0) |
| 441 | { |
| 442 | } |
| 443 | |
| 444 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 445 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 446 | __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) |
| 447 | : __size_alloc_(0, __node_allocator(__a)) |
| 448 | { |
| 449 | } |
| 450 | |
| 451 | template <class _Tp, class _Alloc> |
| 452 | __list_imp<_Tp, _Alloc>::~__list_imp() |
| 453 | { |
| 454 | clear(); |
| 455 | } |
| 456 | |
| 457 | template <class _Tp, class _Alloc> |
| 458 | void |
| 459 | __list_imp<_Tp, _Alloc>::clear() |
| 460 | { |
| 461 | if (!empty()) |
| 462 | { |
| 463 | __node_allocator& __na = __node_alloc(); |
| 464 | iterator __f = begin(); |
| 465 | iterator __l = end(); |
| 466 | __unlink_nodes(*__f.__ptr_, *__l.__ptr_->__prev_); |
| 467 | __sz() = 0; |
| 468 | while (__f != __l) |
| 469 | { |
| 470 | __node& __n = *__f.__ptr_; |
| 471 | ++__f; |
| 472 | __node_alloc_traits::destroy(__na, addressof(__n.__value_)); |
| 473 | __node_alloc_traits::deallocate(__na, addressof(__n), 1); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | template <class _Tp, class _Alloc> |
| 479 | void |
| 480 | __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) |
| 481 | { |
| 482 | using _STD::swap; |
| 483 | __swap_alloc(__node_alloc(), __c.__node_alloc()); |
| 484 | swap(__sz(), __c.__sz()); |
| 485 | swap(__end_, __c.__end_); |
| 486 | if (__sz() == 0) |
| 487 | __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_); |
| 488 | else |
| 489 | __end_.__prev_->__next_ = __end_.__next_->__prev_ |
| 490 | = &static_cast<__node&>(__end_); |
| 491 | if (__c.__sz() == 0) |
| 492 | __c.__end_.__next_ = __c.__end_.__prev_ |
| 493 | = &static_cast<__node&>(__c.__end_); |
| 494 | else |
| 495 | __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ |
| 496 | = &static_cast<__node&>(__c.__end_); |
| 497 | } |
| 498 | |
| 499 | template <class _Tp, class _Alloc = allocator<_Tp> > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 500 | class _LIBCPP_VISIBLE list |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 501 | : private __list_imp<_Tp, _Alloc> |
| 502 | { |
| 503 | typedef __list_imp<_Tp, _Alloc> base; |
| 504 | typedef typename base::__node __node; |
| 505 | typedef typename base::__node_allocator __node_allocator; |
| 506 | typedef typename base::__node_pointer __node_pointer; |
| 507 | typedef typename base::__node_alloc_traits __node_alloc_traits; |
| 508 | |
| 509 | public: |
| 510 | typedef _Tp value_type; |
| 511 | typedef _Alloc allocator_type; |
| 512 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 513 | "Invalid allocator::value_type"); |
| 514 | typedef value_type& reference; |
| 515 | typedef const value_type& const_reference; |
| 516 | typedef typename base::pointer pointer; |
| 517 | typedef typename base::const_pointer const_pointer; |
| 518 | typedef typename base::size_type size_type; |
| 519 | typedef typename base::difference_type difference_type; |
| 520 | typedef typename base::iterator iterator; |
| 521 | typedef typename base::const_iterator const_iterator; |
| 522 | typedef _STD::reverse_iterator<iterator> reverse_iterator; |
| 523 | typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 524 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 525 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | list() {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | list(const allocator_type& __a) : base(__a) {} |
| 529 | list(size_type __n); |
| 530 | list(size_type __n, const value_type& __x); |
| 531 | list(size_type __n, const value_type& __x, const allocator_type& __a); |
| 532 | template <class _InpIter> |
| 533 | list(_InpIter __f, _InpIter __l, |
| 534 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 535 | template <class _InpIter> |
| 536 | list(_InpIter __f, _InpIter __l, const allocator_type& __a, |
| 537 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 538 | |
| 539 | list(const list& __c); |
| 540 | list(const list& __c, const allocator_type& __a); |
| 541 | list& operator=(const list& __c); |
| 542 | list(initializer_list<value_type> __il); |
| 543 | list(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 544 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 545 | list(list&& __c); |
| 546 | list(list&& __c, const allocator_type& __a); |
| 547 | list& operator=(list&& __c); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 548 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 549 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | list& operator=(initializer_list<value_type> __il) |
| 551 | {assign(__il.begin(), __il.end()); return *this;} |
| 552 | |
| 553 | template <class _InpIter> |
| 554 | void assign(_InpIter __f, _InpIter __l, |
| 555 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 556 | void assign(size_type __n, const value_type& __x); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 557 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | void assign(initializer_list<value_type> __il) |
| 559 | {assign(__il.begin(), __il.end());} |
| 560 | |
| 561 | allocator_type get_allocator() const; |
| 562 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 | size_type size() const {return base::__sz();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | bool empty() const {return base::empty();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | size_type max_size() const {return numeric_limits<difference_type>::max();} |
| 569 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | iterator begin() {return base::begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 573 | const_iterator begin() const {return base::begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | iterator end() {return base::end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | const_iterator end() const {return base::end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 579 | const_iterator cbegin() const {return base::begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | const_iterator cend() const {return base::end();} |
| 582 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | reverse_iterator rbegin() {return reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 586 | const_reverse_iterator rbegin() const {return const_reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 587 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | reverse_iterator rend() {return reverse_iterator(begin());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | const_reverse_iterator rend() const {return const_reverse_iterator(begin());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | const_reverse_iterator crbegin() const {return const_reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 593 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | const_reverse_iterator crend() const {return const_reverse_iterator(begin());} |
| 595 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 596 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 597 | reference front() {return base::__end_.__next_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | const_reference front() const {return base::__end_.__next_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 600 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | reference back() {return base::__end_.__prev_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 | const_reference back() const {return base::__end_.__prev_->__value_;} |
| 604 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 605 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | void push_front(value_type&& __x); |
| 607 | void push_back(value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 608 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | template <class... _Args> |
| 610 | void emplace_front(_Args&&... __args); |
| 611 | template <class... _Args> |
| 612 | void emplace_back(_Args&&... __args); |
| 613 | template <class... _Args> |
| 614 | iterator emplace(const_iterator __p, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 615 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | iterator insert(const_iterator __p, value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 617 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 618 | |
| 619 | void push_front(const value_type& __x); |
| 620 | void push_back(const value_type& __x); |
| 621 | |
| 622 | iterator insert(const_iterator __p, const value_type& __x); |
| 623 | iterator insert(const_iterator __p, size_type __n, const value_type& __x); |
| 624 | template <class _InpIter> |
| 625 | iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 626 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 627 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | iterator insert(const_iterator __p, initializer_list<value_type> __il) |
| 629 | {return insert(__p, __il.begin(), __il.end());} |
| 630 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 631 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | void swap(list& __c) {base::swap(__c);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 633 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | void clear() {base::clear();} |
| 635 | |
| 636 | void pop_front(); |
| 637 | void pop_back(); |
| 638 | |
| 639 | iterator erase(const_iterator __p); |
| 640 | iterator erase(const_iterator __f, const_iterator __l); |
| 641 | |
| 642 | void resize(size_type __n); |
| 643 | void resize(size_type __n, const value_type& __x); |
| 644 | |
| 645 | void splice(const_iterator __p, list& __c); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 646 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 647 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | void splice(const_iterator __p, list&& __c) {splice(__p, __c);} |
| 649 | #endif |
| 650 | void splice(const_iterator __p, list& __c, const_iterator __i); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 651 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 652 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | void splice(const_iterator __p, list&& __c, const_iterator __i) |
| 654 | {splice(__p, __c, __i);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 655 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 657 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 658 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 659 | void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) |
| 660 | {splice(__p, __c, __f, __l);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 661 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | |
| 663 | void remove(const value_type& __x); |
| 664 | template <class _Pred> void remove_if(_Pred __pred); |
| 665 | void unique(); |
| 666 | template <class _BinaryPred> |
| 667 | void unique(_BinaryPred __binary_pred); |
| 668 | void merge(list& __c); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 669 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 670 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | void merge(list&& __c) {merge(__c);} |
| 672 | #endif |
| 673 | template <class _Comp> |
| 674 | void merge(list& __c, _Comp __comp); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 675 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | template <class _Comp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 677 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 678 | void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 679 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | void sort(); |
| 681 | template <class _Comp> |
| 682 | void sort(_Comp __comp); |
| 683 | |
| 684 | void reverse(); |
| 685 | |
| 686 | private: |
| 687 | static void __link_nodes(__node& __p, __node& __f, __node& __l); |
| 688 | iterator __iterator(size_type __n); |
| 689 | template <class _Comp> |
| 690 | static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); |
| 691 | |
| 692 | void __move_assign(list& __c, true_type); |
| 693 | void __move_assign(list& __c, false_type); |
| 694 | }; |
| 695 | |
| 696 | // Link in nodes [__f, __l] just prior to __p |
| 697 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 698 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 699 | void |
| 700 | list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l) |
| 701 | { |
| 702 | __p.__prev_->__next_ = &__f; |
| 703 | __f.__prev_ = __p.__prev_; |
| 704 | __p.__prev_ = &__l; |
| 705 | __l.__next_ = &__p; |
| 706 | } |
| 707 | |
| 708 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 709 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | typename list<_Tp, _Alloc>::iterator |
| 711 | list<_Tp, _Alloc>::__iterator(size_type __n) |
| 712 | { |
| 713 | return __n <= base::__sz() / 2 ? next(begin(), __n) |
| 714 | : prev(end(), base::__sz() - __n); |
| 715 | } |
| 716 | |
| 717 | template <class _Tp, class _Alloc> |
| 718 | list<_Tp, _Alloc>::list(size_type __n) |
| 719 | { |
| 720 | for (; __n > 0; --__n) |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 721 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | emplace_back(); |
| 723 | #else |
| 724 | push_back(value_type()); |
| 725 | #endif |
| 726 | } |
| 727 | |
| 728 | template <class _Tp, class _Alloc> |
| 729 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) |
| 730 | { |
| 731 | for (; __n > 0; --__n) |
| 732 | push_back(__x); |
| 733 | } |
| 734 | |
| 735 | template <class _Tp, class _Alloc> |
| 736 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) |
| 737 | : base(__a) |
| 738 | { |
| 739 | for (; __n > 0; --__n) |
| 740 | push_back(__x); |
| 741 | } |
| 742 | |
| 743 | template <class _Tp, class _Alloc> |
| 744 | template <class _InpIter> |
| 745 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, |
| 746 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 747 | { |
| 748 | for (; __f != __l; ++__f) |
| 749 | push_back(*__f); |
| 750 | } |
| 751 | |
| 752 | template <class _Tp, class _Alloc> |
| 753 | template <class _InpIter> |
| 754 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, |
| 755 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 756 | : base(__a) |
| 757 | { |
| 758 | for (; __f != __l; ++__f) |
| 759 | push_back(*__f); |
| 760 | } |
| 761 | |
| 762 | template <class _Tp, class _Alloc> |
| 763 | list<_Tp, _Alloc>::list(const list& __c) |
| 764 | : base(allocator_type( |
| 765 | __node_alloc_traits::select_on_container_copy_construction( |
| 766 | __c.__node_alloc()))) |
| 767 | { |
| 768 | for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) |
| 769 | push_back(*__i); |
| 770 | } |
| 771 | |
| 772 | template <class _Tp, class _Alloc> |
| 773 | list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) |
| 774 | : base(__a) |
| 775 | { |
| 776 | for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) |
| 777 | push_back(*__i); |
| 778 | } |
| 779 | |
| 780 | template <class _Tp, class _Alloc> |
| 781 | list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) |
| 782 | : base(__a) |
| 783 | { |
| 784 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 785 | __e = __il.end(); __i != __e; ++__i) |
| 786 | push_back(*__i); |
| 787 | } |
| 788 | |
| 789 | template <class _Tp, class _Alloc> |
| 790 | list<_Tp, _Alloc>::list(initializer_list<value_type> __il) |
| 791 | { |
| 792 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 793 | __e = __il.end(); __i != __e; ++__i) |
| 794 | push_back(*__i); |
| 795 | } |
| 796 | |
| 797 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 798 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | list<_Tp, _Alloc>& |
| 800 | list<_Tp, _Alloc>::operator=(const list& __c) |
| 801 | { |
| 802 | if (this != &__c) |
| 803 | { |
| 804 | base::__copy_assign_alloc(__c); |
| 805 | assign(__c.begin(), __c.end()); |
| 806 | } |
| 807 | return *this; |
| 808 | } |
| 809 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 810 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 811 | |
| 812 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 813 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 814 | list<_Tp, _Alloc>::list(list&& __c) |
| 815 | : base(allocator_type(_STD::move(__c.__node_alloc()))) |
| 816 | { |
| 817 | splice(end(), __c); |
| 818 | } |
| 819 | |
| 820 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 821 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 822 | list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) |
| 823 | : base(__a) |
| 824 | { |
| 825 | if (__a == __c.get_allocator()) |
| 826 | splice(end(), __c); |
| 827 | else |
| 828 | { |
| 829 | typedef move_iterator<iterator> _I; |
| 830 | assign(_I(__c.begin()), _I(__c.end())); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 835 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | list<_Tp, _Alloc>& |
| 837 | list<_Tp, _Alloc>::operator=(list&& __c) |
| 838 | { |
| 839 | __move_assign(__c, integral_constant<bool, |
| 840 | __node_alloc_traits::propagate_on_container_move_assignment::value>()); |
| 841 | return *this; |
| 842 | } |
| 843 | |
| 844 | template <class _Tp, class _Alloc> |
| 845 | void |
| 846 | list<_Tp, _Alloc>::__move_assign(list& __c, false_type) |
| 847 | { |
| 848 | if (base::__node_alloc() != __c.__node_alloc()) |
| 849 | { |
| 850 | typedef move_iterator<iterator> _I; |
| 851 | assign(_I(__c.begin()), _I(__c.end())); |
| 852 | } |
| 853 | else |
| 854 | __move_assign(__c, true_type()); |
| 855 | } |
| 856 | |
| 857 | template <class _Tp, class _Alloc> |
| 858 | void |
| 859 | list<_Tp, _Alloc>::__move_assign(list& __c, true_type) |
| 860 | { |
| 861 | clear(); |
| 862 | base::__move_assign_alloc(__c); |
| 863 | splice(end(), __c); |
| 864 | } |
| 865 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 866 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | |
| 868 | template <class _Tp, class _Alloc> |
| 869 | template <class _InpIter> |
| 870 | void |
| 871 | list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, |
| 872 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 873 | { |
| 874 | iterator __i = begin(); |
| 875 | iterator __e = end(); |
| 876 | for (; __f != __l && __i != __e; ++__f, ++__i) |
| 877 | *__i = *__f; |
| 878 | if (__i == __e) |
| 879 | insert(__e, __f, __l); |
| 880 | else |
| 881 | erase(__i, __e); |
| 882 | } |
| 883 | |
| 884 | template <class _Tp, class _Alloc> |
| 885 | void |
| 886 | list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) |
| 887 | { |
| 888 | iterator __i = begin(); |
| 889 | iterator __e = end(); |
| 890 | for (; __n > 0 && __i != __e; --__n, ++__i) |
| 891 | *__i = __x; |
| 892 | if (__i == __e) |
| 893 | insert(__e, __n, __x); |
| 894 | else |
| 895 | erase(__i, __e); |
| 896 | } |
| 897 | |
| 898 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 899 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | _Alloc |
| 901 | list<_Tp, _Alloc>::get_allocator() const |
| 902 | { |
| 903 | return allocator_type(base::__node_alloc()); |
| 904 | } |
| 905 | |
| 906 | template <class _Tp, class _Alloc> |
| 907 | typename list<_Tp, _Alloc>::iterator |
| 908 | list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) |
| 909 | { |
| 910 | __node_allocator& __na = base::__node_alloc(); |
| 911 | typedef __allocator_destructor<__node_allocator> _D; |
| 912 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 913 | __hold->__prev_ = 0; |
| 914 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 915 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 916 | ++base::__sz(); |
| 917 | return iterator(__hold.release()); |
| 918 | } |
| 919 | |
| 920 | template <class _Tp, class _Alloc> |
| 921 | typename list<_Tp, _Alloc>::iterator |
| 922 | list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) |
| 923 | { |
| 924 | iterator __r(const_cast<__node_pointer>(__p.__ptr_)); |
| 925 | if (__n > 0) |
| 926 | { |
| 927 | size_type __ds = 0; |
| 928 | __node_allocator& __na = base::__node_alloc(); |
| 929 | typedef __allocator_destructor<__node_allocator> _D; |
| 930 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 931 | __hold->__prev_ = 0; |
| 932 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 933 | ++__ds; |
| 934 | __r = iterator(__hold.get()); |
| 935 | __hold.release(); |
| 936 | iterator __e = __r; |
| 937 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 938 | try |
| 939 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 940 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 941 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 942 | { |
| 943 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
| 944 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 945 | __e.__ptr_->__next_ = __hold.get(); |
| 946 | __hold->__prev_ = __e.__ptr_; |
| 947 | __hold.release(); |
| 948 | } |
| 949 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 950 | } |
| 951 | catch (...) |
| 952 | { |
| 953 | while (true) |
| 954 | { |
| 955 | __node_alloc_traits::destroy(__na, addressof(*__e)); |
| 956 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 957 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 958 | if (__prev == 0) |
| 959 | break; |
| 960 | __e = iterator(__prev); |
| 961 | } |
| 962 | throw; |
| 963 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 964 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); |
| 966 | base::__sz() += __ds; |
| 967 | } |
| 968 | return __r; |
| 969 | } |
| 970 | |
| 971 | template <class _Tp, class _Alloc> |
| 972 | template <class _InpIter> |
| 973 | typename list<_Tp, _Alloc>::iterator |
| 974 | list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 975 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 976 | { |
| 977 | iterator __r(const_cast<__node_pointer>(__p.__ptr_)); |
| 978 | if (__f != __l) |
| 979 | { |
| 980 | size_type __ds = 0; |
| 981 | __node_allocator& __na = base::__node_alloc(); |
| 982 | typedef __allocator_destructor<__node_allocator> _D; |
| 983 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 984 | __hold->__prev_ = 0; |
| 985 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), *__f); |
| 986 | ++__ds; |
| 987 | __r = iterator(__hold.get()); |
| 988 | __hold.release(); |
| 989 | iterator __e = __r; |
| 990 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 991 | try |
| 992 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 993 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | for (++__f; __f != __l; ++__f, ++__e, ++__ds) |
| 995 | { |
| 996 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
| 997 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), *__f); |
| 998 | __e.__ptr_->__next_ = __hold.get(); |
| 999 | __hold->__prev_ = __e.__ptr_; |
| 1000 | __hold.release(); |
| 1001 | } |
| 1002 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1003 | } |
| 1004 | catch (...) |
| 1005 | { |
| 1006 | while (true) |
| 1007 | { |
| 1008 | __node_alloc_traits::destroy(__na, addressof(*__e)); |
| 1009 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1010 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1011 | if (__prev == 0) |
| 1012 | break; |
| 1013 | __e = iterator(__prev); |
| 1014 | } |
| 1015 | throw; |
| 1016 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1017 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); |
| 1019 | base::__sz() += __ds; |
| 1020 | } |
| 1021 | return __r; |
| 1022 | } |
| 1023 | |
| 1024 | template <class _Tp, class _Alloc> |
| 1025 | void |
| 1026 | list<_Tp, _Alloc>::push_front(const value_type& __x) |
| 1027 | { |
| 1028 | __node_allocator& __na = base::__node_alloc(); |
| 1029 | typedef __allocator_destructor<__node_allocator> _D; |
| 1030 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1031 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 1032 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1033 | ++base::__sz(); |
| 1034 | __hold.release(); |
| 1035 | } |
| 1036 | |
| 1037 | template <class _Tp, class _Alloc> |
| 1038 | void |
| 1039 | list<_Tp, _Alloc>::push_back(const value_type& __x) |
| 1040 | { |
| 1041 | __node_allocator& __na = base::__node_alloc(); |
| 1042 | typedef __allocator_destructor<__node_allocator> _D; |
| 1043 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1044 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 1045 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1046 | ++base::__sz(); |
| 1047 | __hold.release(); |
| 1048 | } |
| 1049 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1050 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | |
| 1052 | template <class _Tp, class _Alloc> |
| 1053 | void |
| 1054 | list<_Tp, _Alloc>::push_front(value_type&& __x) |
| 1055 | { |
| 1056 | __node_allocator& __na = base::__node_alloc(); |
| 1057 | typedef __allocator_destructor<__node_allocator> _D; |
| 1058 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1059 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x)); |
| 1060 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1061 | ++base::__sz(); |
| 1062 | __hold.release(); |
| 1063 | } |
| 1064 | |
| 1065 | template <class _Tp, class _Alloc> |
| 1066 | void |
| 1067 | list<_Tp, _Alloc>::push_back(value_type&& __x) |
| 1068 | { |
| 1069 | __node_allocator& __na = base::__node_alloc(); |
| 1070 | typedef __allocator_destructor<__node_allocator> _D; |
| 1071 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1072 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x)); |
| 1073 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1074 | ++base::__sz(); |
| 1075 | __hold.release(); |
| 1076 | } |
| 1077 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1078 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1079 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1080 | template <class _Tp, class _Alloc> |
| 1081 | template <class... _Args> |
| 1082 | void |
| 1083 | list<_Tp, _Alloc>::emplace_front(_Args&&... __args) |
| 1084 | { |
| 1085 | __node_allocator& __na = base::__node_alloc(); |
| 1086 | typedef __allocator_destructor<__node_allocator> _D; |
| 1087 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1088 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
| 1089 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1090 | ++base::__sz(); |
| 1091 | __hold.release(); |
| 1092 | } |
| 1093 | |
| 1094 | template <class _Tp, class _Alloc> |
| 1095 | template <class... _Args> |
| 1096 | void |
| 1097 | list<_Tp, _Alloc>::emplace_back(_Args&&... __args) |
| 1098 | { |
| 1099 | __node_allocator& __na = base::__node_alloc(); |
| 1100 | typedef __allocator_destructor<__node_allocator> _D; |
| 1101 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1102 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
| 1103 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1104 | ++base::__sz(); |
| 1105 | __hold.release(); |
| 1106 | } |
| 1107 | |
| 1108 | template <class _Tp, class _Alloc> |
| 1109 | template <class... _Args> |
| 1110 | typename list<_Tp, _Alloc>::iterator |
| 1111 | list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) |
| 1112 | { |
| 1113 | __node_allocator& __na = base::__node_alloc(); |
| 1114 | typedef __allocator_destructor<__node_allocator> _D; |
| 1115 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1116 | __hold->__prev_ = 0; |
| 1117 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
| 1118 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 1119 | ++base::__sz(); |
| 1120 | return iterator(__hold.release()); |
| 1121 | } |
| 1122 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1123 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1124 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 | template <class _Tp, class _Alloc> |
| 1126 | typename list<_Tp, _Alloc>::iterator |
| 1127 | list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) |
| 1128 | { |
| 1129 | __node_allocator& __na = base::__node_alloc(); |
| 1130 | typedef __allocator_destructor<__node_allocator> _D; |
| 1131 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1132 | __hold->__prev_ = 0; |
| 1133 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x)); |
| 1134 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 1135 | ++base::__sz(); |
| 1136 | return iterator(__hold.release()); |
| 1137 | } |
| 1138 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1139 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | |
| 1141 | template <class _Tp, class _Alloc> |
| 1142 | void |
| 1143 | list<_Tp, _Alloc>::pop_front() |
| 1144 | { |
| 1145 | __node_allocator& __na = base::__node_alloc(); |
| 1146 | __node& __n = *base::__end_.__next_; |
| 1147 | base::__unlink_nodes(__n, __n); |
| 1148 | --base::__sz(); |
| 1149 | __node_alloc_traits::destroy(__na, addressof(__n.__value_)); |
| 1150 | __node_alloc_traits::deallocate(__na, addressof(__n), 1); |
| 1151 | } |
| 1152 | |
| 1153 | template <class _Tp, class _Alloc> |
| 1154 | void |
| 1155 | list<_Tp, _Alloc>::pop_back() |
| 1156 | { |
| 1157 | __node_allocator& __na = base::__node_alloc(); |
| 1158 | __node& __n = *base::__end_.__prev_; |
| 1159 | base::__unlink_nodes(__n, __n); |
| 1160 | --base::__sz(); |
| 1161 | __node_alloc_traits::destroy(__na, addressof(__n.__value_)); |
| 1162 | __node_alloc_traits::deallocate(__na, addressof(__n), 1); |
| 1163 | } |
| 1164 | |
| 1165 | template <class _Tp, class _Alloc> |
| 1166 | typename list<_Tp, _Alloc>::iterator |
| 1167 | list<_Tp, _Alloc>::erase(const_iterator __p) |
| 1168 | { |
| 1169 | __node_allocator& __na = base::__node_alloc(); |
| 1170 | __node& __n = const_cast<__node&>(*__p.__ptr_); |
| 1171 | __node_pointer __r = __n.__next_; |
| 1172 | base::__unlink_nodes(__n, __n); |
| 1173 | --base::__sz(); |
| 1174 | __node_alloc_traits::destroy(__na, addressof(__n.__value_)); |
| 1175 | __node_alloc_traits::deallocate(__na, addressof(__n), 1); |
| 1176 | return iterator(__r); |
| 1177 | } |
| 1178 | |
| 1179 | template <class _Tp, class _Alloc> |
| 1180 | typename list<_Tp, _Alloc>::iterator |
| 1181 | list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) |
| 1182 | { |
| 1183 | if (__f != __l) |
| 1184 | { |
| 1185 | __node_allocator& __na = base::__node_alloc(); |
| 1186 | base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_); |
| 1187 | while (__f != __l) |
| 1188 | { |
| 1189 | __node& __n = const_cast<__node&>(*__f.__ptr_); |
| 1190 | ++__f; |
| 1191 | --base::__sz(); |
| 1192 | __node_alloc_traits::destroy(__na, addressof(__n.__value_)); |
| 1193 | __node_alloc_traits::deallocate(__na, addressof(__n), 1); |
| 1194 | } |
| 1195 | } |
| 1196 | return iterator(const_cast<__node_pointer>(__l.__ptr_)); |
| 1197 | } |
| 1198 | |
| 1199 | template <class _Tp, class _Alloc> |
| 1200 | void |
| 1201 | list<_Tp, _Alloc>::resize(size_type __n) |
| 1202 | { |
| 1203 | if (__n < base::__sz()) |
| 1204 | erase(__iterator(__n), end()); |
| 1205 | else if (__n > base::__sz()) |
| 1206 | { |
| 1207 | __n -= base::__sz(); |
| 1208 | size_type __ds = 0; |
| 1209 | __node_allocator& __na = base::__node_alloc(); |
| 1210 | typedef __allocator_destructor<__node_allocator> _D; |
| 1211 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1212 | __hold->__prev_ = 0; |
| 1213 | __node_alloc_traits::construct(__na, addressof(__hold->__value_)); |
| 1214 | ++__ds; |
| 1215 | iterator __r = iterator(__hold.release()); |
| 1216 | iterator __e = __r; |
| 1217 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1218 | try |
| 1219 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1220 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1222 | { |
| 1223 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
| 1224 | __node_alloc_traits::construct(__na, addressof(__hold->__value_)); |
| 1225 | __e.__ptr_->__next_ = __hold.get(); |
| 1226 | __hold->__prev_ = __e.__ptr_; |
| 1227 | __hold.release(); |
| 1228 | } |
| 1229 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1230 | } |
| 1231 | catch (...) |
| 1232 | { |
| 1233 | while (true) |
| 1234 | { |
| 1235 | __node_alloc_traits::destroy(__na, addressof(*__e)); |
| 1236 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1237 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1238 | if (__prev == 0) |
| 1239 | break; |
| 1240 | __e = iterator(__prev); |
| 1241 | } |
| 1242 | throw; |
| 1243 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1244 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1245 | __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); |
| 1246 | base::__sz() += __ds; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | template <class _Tp, class _Alloc> |
| 1251 | void |
| 1252 | list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) |
| 1253 | { |
| 1254 | if (__n < base::__sz()) |
| 1255 | erase(__iterator(__n), end()); |
| 1256 | else if (__n > base::__sz()) |
| 1257 | { |
| 1258 | __n -= base::__sz(); |
| 1259 | size_type __ds = 0; |
| 1260 | __node_allocator& __na = base::__node_alloc(); |
| 1261 | typedef __allocator_destructor<__node_allocator> _D; |
| 1262 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1263 | __hold->__prev_ = 0; |
| 1264 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 1265 | ++__ds; |
| 1266 | iterator __r = iterator(__hold.release()); |
| 1267 | iterator __e = __r; |
| 1268 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1269 | try |
| 1270 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1271 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1272 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1273 | { |
| 1274 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
| 1275 | __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x); |
| 1276 | __e.__ptr_->__next_ = __hold.get(); |
| 1277 | __hold->__prev_ = __e.__ptr_; |
| 1278 | __hold.release(); |
| 1279 | } |
| 1280 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1281 | } |
| 1282 | catch (...) |
| 1283 | { |
| 1284 | while (true) |
| 1285 | { |
| 1286 | __node_alloc_traits::destroy(__na, addressof(*__e)); |
| 1287 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1288 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1289 | if (__prev == 0) |
| 1290 | break; |
| 1291 | __e = iterator(__prev); |
| 1292 | } |
| 1293 | throw; |
| 1294 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1295 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1296 | __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); |
| 1297 | base::__sz() += __ds; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1298 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | template <class _Tp, class _Alloc> |
| 1302 | void |
| 1303 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) |
| 1304 | { |
| 1305 | if (!__c.empty()) |
| 1306 | { |
| 1307 | __node& __f = *__c.__end_.__next_; |
| 1308 | __node& __l = *__c.__end_.__prev_; |
| 1309 | base::__unlink_nodes(__f, __l); |
| 1310 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l); |
| 1311 | base::__sz() += __c.__sz(); |
| 1312 | __c.__sz() = 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | template <class _Tp, class _Alloc> |
| 1317 | void |
| 1318 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) |
| 1319 | { |
| 1320 | if (__p != __i && __p != next(__i)) |
| 1321 | { |
| 1322 | __node& __f = const_cast<__node&>(*__i.__ptr_); |
| 1323 | base::__unlink_nodes(__f, __f); |
| 1324 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f); |
| 1325 | --__c.__sz(); |
| 1326 | ++base::__sz(); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | template <class _Tp, class _Alloc> |
| 1331 | void |
| 1332 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) |
| 1333 | { |
| 1334 | if (__f != __l) |
| 1335 | { |
| 1336 | if (this != &__c) |
| 1337 | { |
| 1338 | size_type __s = _STD::distance(__f, __l); |
| 1339 | __c.__sz() -= __s; |
| 1340 | base::__sz() += __s; |
| 1341 | } |
| 1342 | __node& __first = const_cast<__node&>(*__f.__ptr_); |
| 1343 | --__l; |
| 1344 | __node& __last = const_cast<__node&>(*__l.__ptr_); |
| 1345 | base::__unlink_nodes(__first, __last); |
| 1346 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | template <class _Tp, class _Alloc> |
| 1351 | void |
| 1352 | list<_Tp, _Alloc>::remove(const value_type& __x) |
| 1353 | { |
| 1354 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1355 | { |
| 1356 | if (*__i == __x) |
| 1357 | { |
| 1358 | iterator __j = next(__i); |
| 1359 | for (; __j != __e && *__j == __x; ++__j) |
| 1360 | ; |
| 1361 | __i = erase(__i, __j); |
| 1362 | } |
| 1363 | else |
| 1364 | ++__i; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | template <class _Tp, class _Alloc> |
| 1369 | template <class _Pred> |
| 1370 | void |
| 1371 | list<_Tp, _Alloc>::remove_if(_Pred __pred) |
| 1372 | { |
| 1373 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1374 | { |
| 1375 | if (__pred(*__i)) |
| 1376 | { |
| 1377 | iterator __j = next(__i); |
| 1378 | for (; __j != __e && __pred(*__j); ++__j) |
| 1379 | ; |
| 1380 | __i = erase(__i, __j); |
| 1381 | } |
| 1382 | else |
| 1383 | ++__i; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1388 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | void |
| 1390 | list<_Tp, _Alloc>::unique() |
| 1391 | { |
| 1392 | unique(__equal_to<value_type>()); |
| 1393 | } |
| 1394 | |
| 1395 | template <class _Tp, class _Alloc> |
| 1396 | template <class _BinaryPred> |
| 1397 | void |
| 1398 | list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) |
| 1399 | { |
| 1400 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1401 | { |
| 1402 | iterator __j = next(__i); |
| 1403 | for (; __j != __e && __binary_pred(*__i, *__j); ++__j) |
| 1404 | ; |
| 1405 | if (++__i != __j) |
| 1406 | __i = erase(__i, __j); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1411 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | void |
| 1413 | list<_Tp, _Alloc>::merge(list& __c) |
| 1414 | { |
| 1415 | merge(__c, __less<value_type>()); |
| 1416 | } |
| 1417 | |
| 1418 | template <class _Tp, class _Alloc> |
| 1419 | template <class _Comp> |
| 1420 | void |
| 1421 | list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) |
| 1422 | { |
| 1423 | if (this != &__c) |
| 1424 | { |
| 1425 | iterator __f1 = begin(); |
| 1426 | iterator __e1 = end(); |
| 1427 | iterator __f2 = __c.begin(); |
| 1428 | iterator __e2 = __c.end(); |
| 1429 | while (__f1 != __e1 && __f2 != __e2) |
| 1430 | { |
| 1431 | if (__comp(*__f2, *__f1)) |
| 1432 | { |
| 1433 | size_type __ds = 1; |
| 1434 | iterator __m2 = next(__f2); |
| 1435 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) |
| 1436 | ; |
| 1437 | base::__sz() += __ds; |
| 1438 | __c.__sz() -= __ds; |
| 1439 | __node& __f = *__f2.__ptr_; |
| 1440 | __node& __l = *__m2.__ptr_->__prev_; |
| 1441 | __f2 = __m2; |
| 1442 | base::__unlink_nodes(__f, __l); |
| 1443 | __m2 = next(__f1); |
| 1444 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1445 | __f1 = __m2; |
| 1446 | } |
| 1447 | else |
| 1448 | ++__f1; |
| 1449 | } |
| 1450 | splice(__e1, __c); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1455 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | void |
| 1457 | list<_Tp, _Alloc>::sort() |
| 1458 | { |
| 1459 | sort(__less<value_type>()); |
| 1460 | } |
| 1461 | |
| 1462 | template <class _Tp, class _Alloc> |
| 1463 | template <class _Comp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1464 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1465 | void |
| 1466 | list<_Tp, _Alloc>::sort(_Comp __comp) |
| 1467 | { |
| 1468 | __sort(begin(), end(), base::__sz(), __comp); |
| 1469 | } |
| 1470 | |
| 1471 | template <class _Tp, class _Alloc> |
| 1472 | template <class _Comp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1473 | typename list<_Tp, _Alloc>::iterator |
| 1474 | list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) |
| 1475 | { |
| 1476 | switch (__n) |
| 1477 | { |
| 1478 | case 0: |
| 1479 | case 1: |
| 1480 | return __f1; |
| 1481 | case 2: |
| 1482 | if (__comp(*--__e2, *__f1)) |
| 1483 | { |
| 1484 | __node& __f = *__e2.__ptr_; |
| 1485 | base::__unlink_nodes(__f, __f); |
| 1486 | __link_nodes(*__f1.__ptr_, __f, __f); |
| 1487 | return __e2; |
| 1488 | } |
| 1489 | return __f1; |
| 1490 | } |
| 1491 | size_type __n2 = __n / 2; |
| 1492 | iterator __e1 = next(__f1, __n2); |
| 1493 | iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); |
| 1494 | iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); |
| 1495 | if (__comp(*__f2, *__f1)) |
| 1496 | { |
| 1497 | iterator __m2 = next(__f2); |
| 1498 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 1499 | ; |
| 1500 | __node& __f = *__f2.__ptr_; |
| 1501 | __node& __l = *__m2.__ptr_->__prev_; |
| 1502 | __r = __f2; |
| 1503 | __e1 = __f2 = __m2; |
| 1504 | base::__unlink_nodes(__f, __l); |
| 1505 | __m2 = next(__f1); |
| 1506 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1507 | __f1 = __m2; |
| 1508 | } |
| 1509 | else |
| 1510 | ++__f1; |
| 1511 | while (__f1 != __e1 && __f2 != __e2) |
| 1512 | { |
| 1513 | if (__comp(*__f2, *__f1)) |
| 1514 | { |
| 1515 | iterator __m2 = next(__f2); |
| 1516 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 1517 | ; |
| 1518 | __node& __f = *__f2.__ptr_; |
| 1519 | __node& __l = *__m2.__ptr_->__prev_; |
| 1520 | if (__e1 == __f2) |
| 1521 | __e1 = __m2; |
| 1522 | __f2 = __m2; |
| 1523 | base::__unlink_nodes(__f, __l); |
| 1524 | __m2 = next(__f1); |
| 1525 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1526 | __f1 = __m2; |
| 1527 | } |
| 1528 | else |
| 1529 | ++__f1; |
| 1530 | } |
| 1531 | return __r; |
| 1532 | } |
| 1533 | |
| 1534 | template <class _Tp, class _Alloc> |
| 1535 | void |
| 1536 | list<_Tp, _Alloc>::reverse() |
| 1537 | { |
| 1538 | if (base::__sz() > 1) |
| 1539 | { |
| 1540 | iterator __e = end(); |
| 1541 | for (iterator __i = begin(); __i != __e; --__i) |
| 1542 | _STD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); |
| 1543 | _STD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1548 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1549 | bool |
| 1550 | operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1551 | { |
| 1552 | return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin()); |
| 1553 | } |
| 1554 | |
| 1555 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1556 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1557 | bool |
| 1558 | operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1559 | { |
| 1560 | return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 1561 | } |
| 1562 | |
| 1563 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1564 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1565 | bool |
| 1566 | operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1567 | { |
| 1568 | return !(__x == __y); |
| 1569 | } |
| 1570 | |
| 1571 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1572 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1573 | bool |
| 1574 | operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1575 | { |
| 1576 | return __y < __x; |
| 1577 | } |
| 1578 | |
| 1579 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1580 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1581 | bool |
| 1582 | operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1583 | { |
| 1584 | return !(__x < __y); |
| 1585 | } |
| 1586 | |
| 1587 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1588 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1589 | bool |
| 1590 | operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1591 | { |
| 1592 | return !(__y < __x); |
| 1593 | } |
| 1594 | |
| 1595 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame^] | 1596 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | void |
| 1598 | swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) |
| 1599 | { |
| 1600 | __x.swap(__y); |
| 1601 | } |
| 1602 | |
| 1603 | _LIBCPP_END_NAMESPACE_STD |
| 1604 | |
| 1605 | #endif // _LIBCPP_LIST |