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