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 | |
| 183 | template <class, class> struct __list_node; |
| 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 | |
| 212 | template <class, class> class list; |
| 213 | template <class, class> class __list_imp; |
| 214 | template <class, class> class __list_const_iterator; |
| 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 | { |
| 426 | using _STD::swap; |
| 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 447 | void __move_assign_alloc(const __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 | { |
| 450 | __node_alloc() = _STD::move(__c.__node_alloc()); |
| 451 | } |
| 452 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | void __move_assign_alloc(const __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 | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 506 | __node_alloc_traits::destroy(__na, _STD::addressof(__n.__value_)); |
| 507 | __node_alloc_traits::deallocate(__na, _STD::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 | { |
| 518 | using _STD::swap; |
| 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; |
| 558 | typedef _STD::reverse_iterator<iterator> reverse_iterator; |
| 559 | typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 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); |
| 580 | list(initializer_list<value_type> __il); |
| 581 | list(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 582 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 583 | list(list&& __c) |
| 584 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 585 | list(list&& __c, const allocator_type& __a); |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 586 | list& operator=(list&& __c) |
| 587 | _NOEXCEPT_( |
| 588 | __node_alloc_traits::propagate_on_container_move_assignment::value && |
| 589 | is_nothrow_move_assignable<__node_allocator>::value); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 590 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | list& operator=(initializer_list<value_type> __il) |
| 593 | {assign(__il.begin(), __il.end()); return *this;} |
| 594 | |
| 595 | template <class _InpIter> |
| 596 | void assign(_InpIter __f, _InpIter __l, |
| 597 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 598 | void assign(size_type __n, const value_type& __x); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 599 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | void assign(initializer_list<value_type> __il) |
| 601 | {assign(__il.begin(), __il.end());} |
| 602 | |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 603 | allocator_type get_allocator() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 606 | size_type size() const _NOEXCEPT {return base::__sz();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 607 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 608 | bool empty() const _NOEXCEPT {return base::empty();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 609 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 610 | size_type max_size() const _NOEXCEPT |
| 611 | {return numeric_limits<difference_type>::max();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 612 | |
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 | iterator begin() _NOEXCEPT {return base::begin();} |
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 | const_iterator begin() const _NOEXCEPT {return base::begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 618 | iterator end() _NOEXCEPT {return base::end();} |
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 | const_iterator end() const _NOEXCEPT {return base::end();} |
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 cbegin() 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 | const_iterator cend() const _NOEXCEPT {return base::end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 626 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 627 | reverse_iterator rbegin() _NOEXCEPT |
| 628 | {return reverse_iterator(end());} |
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_reverse_iterator rbegin() const _NOEXCEPT |
| 631 | {return const_reverse_iterator(end());} |
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 rend() _NOEXCEPT |
| 634 | {return reverse_iterator(begin());} |
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 rend() const _NOEXCEPT |
| 637 | {return const_reverse_iterator(begin());} |
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 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 640 | {return const_reverse_iterator(end());} |
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 crend() const _NOEXCEPT |
| 643 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | reference front() {return base::__end_.__next_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 647 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | const_reference front() const {return base::__end_.__next_->__value_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 649 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 650 | reference back() {return base::__end_.__prev_->__value_;} |
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 | const_reference back() const {return base::__end_.__prev_->__value_;} |
| 653 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 654 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | void push_front(value_type&& __x); |
| 656 | void push_back(value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 657 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | template <class... _Args> |
| 659 | void emplace_front(_Args&&... __args); |
| 660 | template <class... _Args> |
| 661 | void emplace_back(_Args&&... __args); |
| 662 | template <class... _Args> |
| 663 | iterator emplace(const_iterator __p, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 664 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | iterator insert(const_iterator __p, value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 666 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | |
| 668 | void push_front(const value_type& __x); |
| 669 | void push_back(const value_type& __x); |
| 670 | |
| 671 | iterator insert(const_iterator __p, const value_type& __x); |
| 672 | iterator insert(const_iterator __p, size_type __n, const value_type& __x); |
| 673 | template <class _InpIter> |
| 674 | iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 675 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 676 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 677 | iterator insert(const_iterator __p, initializer_list<value_type> __il) |
| 678 | {return insert(__p, __il.begin(), __il.end());} |
| 679 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 681 | void swap(list& __c) |
| 682 | _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || |
| 683 | __is_nothrow_swappable<__node_allocator>::value) |
| 684 | {base::swap(__c);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 686 | void clear() _NOEXCEPT {base::clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | |
| 688 | void pop_front(); |
| 689 | void pop_back(); |
| 690 | |
| 691 | iterator erase(const_iterator __p); |
| 692 | iterator erase(const_iterator __f, const_iterator __l); |
| 693 | |
| 694 | void resize(size_type __n); |
| 695 | void resize(size_type __n, const value_type& __x); |
| 696 | |
| 697 | void splice(const_iterator __p, list& __c); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 698 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 699 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 700 | void splice(const_iterator __p, list&& __c) {splice(__p, __c);} |
| 701 | #endif |
| 702 | void splice(const_iterator __p, list& __c, const_iterator __i); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 703 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | void splice(const_iterator __p, list&& __c, const_iterator __i) |
| 706 | {splice(__p, __c, __i);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 707 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | 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] | 709 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 710 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) |
| 712 | {splice(__p, __c, __f, __l);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 713 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 714 | |
| 715 | void remove(const value_type& __x); |
| 716 | template <class _Pred> void remove_if(_Pred __pred); |
| 717 | void unique(); |
| 718 | template <class _BinaryPred> |
| 719 | void unique(_BinaryPred __binary_pred); |
| 720 | void merge(list& __c); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 721 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 722 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | void merge(list&& __c) {merge(__c);} |
| 724 | #endif |
| 725 | template <class _Comp> |
| 726 | void merge(list& __c, _Comp __comp); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 727 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 728 | template <class _Comp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 729 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 730 | void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 731 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | void sort(); |
| 733 | template <class _Comp> |
| 734 | void sort(_Comp __comp); |
| 735 | |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 736 | void reverse() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 737 | |
| 738 | private: |
| 739 | static void __link_nodes(__node& __p, __node& __f, __node& __l); |
| 740 | iterator __iterator(size_type __n); |
| 741 | template <class _Comp> |
| 742 | static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); |
| 743 | |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 744 | void __move_assign(list& __c, true_type) |
| 745 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | void __move_assign(list& __c, false_type); |
| 747 | }; |
| 748 | |
| 749 | // Link in nodes [__f, __l] just prior to __p |
| 750 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 751 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 752 | void |
| 753 | list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l) |
| 754 | { |
| 755 | __p.__prev_->__next_ = &__f; |
| 756 | __f.__prev_ = __p.__prev_; |
| 757 | __p.__prev_ = &__l; |
| 758 | __l.__next_ = &__p; |
| 759 | } |
| 760 | |
| 761 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 762 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 763 | typename list<_Tp, _Alloc>::iterator |
| 764 | list<_Tp, _Alloc>::__iterator(size_type __n) |
| 765 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 766 | return __n <= base::__sz() / 2 ? _STD::next(begin(), __n) |
| 767 | : _STD::prev(end(), base::__sz() - __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | template <class _Tp, class _Alloc> |
| 771 | list<_Tp, _Alloc>::list(size_type __n) |
| 772 | { |
| 773 | for (; __n > 0; --__n) |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 774 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 775 | emplace_back(); |
| 776 | #else |
| 777 | push_back(value_type()); |
| 778 | #endif |
| 779 | } |
| 780 | |
| 781 | template <class _Tp, class _Alloc> |
| 782 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) |
| 783 | { |
| 784 | for (; __n > 0; --__n) |
| 785 | push_back(__x); |
| 786 | } |
| 787 | |
| 788 | template <class _Tp, class _Alloc> |
| 789 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) |
| 790 | : base(__a) |
| 791 | { |
| 792 | for (; __n > 0; --__n) |
| 793 | push_back(__x); |
| 794 | } |
| 795 | |
| 796 | template <class _Tp, class _Alloc> |
| 797 | template <class _InpIter> |
| 798 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, |
| 799 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 800 | { |
| 801 | for (; __f != __l; ++__f) |
| 802 | push_back(*__f); |
| 803 | } |
| 804 | |
| 805 | template <class _Tp, class _Alloc> |
| 806 | template <class _InpIter> |
| 807 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, |
| 808 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 809 | : base(__a) |
| 810 | { |
| 811 | for (; __f != __l; ++__f) |
| 812 | push_back(*__f); |
| 813 | } |
| 814 | |
| 815 | template <class _Tp, class _Alloc> |
| 816 | list<_Tp, _Alloc>::list(const list& __c) |
| 817 | : base(allocator_type( |
| 818 | __node_alloc_traits::select_on_container_copy_construction( |
| 819 | __c.__node_alloc()))) |
| 820 | { |
| 821 | for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) |
| 822 | push_back(*__i); |
| 823 | } |
| 824 | |
| 825 | template <class _Tp, class _Alloc> |
| 826 | list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) |
| 827 | : base(__a) |
| 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(initializer_list<value_type> __il, const allocator_type& __a) |
| 835 | : base(__a) |
| 836 | { |
| 837 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 838 | __e = __il.end(); __i != __e; ++__i) |
| 839 | push_back(*__i); |
| 840 | } |
| 841 | |
| 842 | template <class _Tp, class _Alloc> |
| 843 | list<_Tp, _Alloc>::list(initializer_list<value_type> __il) |
| 844 | { |
| 845 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 846 | __e = __il.end(); __i != __e; ++__i) |
| 847 | push_back(*__i); |
| 848 | } |
| 849 | |
| 850 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 851 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | list<_Tp, _Alloc>& |
| 853 | list<_Tp, _Alloc>::operator=(const list& __c) |
| 854 | { |
| 855 | if (this != &__c) |
| 856 | { |
| 857 | base::__copy_assign_alloc(__c); |
| 858 | assign(__c.begin(), __c.end()); |
| 859 | } |
| 860 | return *this; |
| 861 | } |
| 862 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 863 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | |
| 865 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 866 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | list<_Tp, _Alloc>::list(list&& __c) |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 868 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 869 | : base(allocator_type(_STD::move(__c.__node_alloc()))) |
| 870 | { |
| 871 | splice(end(), __c); |
| 872 | } |
| 873 | |
| 874 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 875 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 876 | list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) |
| 877 | : base(__a) |
| 878 | { |
| 879 | if (__a == __c.get_allocator()) |
| 880 | splice(end(), __c); |
| 881 | else |
| 882 | { |
| 883 | typedef move_iterator<iterator> _I; |
| 884 | assign(_I(__c.begin()), _I(__c.end())); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 889 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | list<_Tp, _Alloc>& |
| 891 | list<_Tp, _Alloc>::operator=(list&& __c) |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 892 | _NOEXCEPT_( |
| 893 | __node_alloc_traits::propagate_on_container_move_assignment::value && |
| 894 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 895 | { |
| 896 | __move_assign(__c, integral_constant<bool, |
| 897 | __node_alloc_traits::propagate_on_container_move_assignment::value>()); |
| 898 | return *this; |
| 899 | } |
| 900 | |
| 901 | template <class _Tp, class _Alloc> |
| 902 | void |
| 903 | list<_Tp, _Alloc>::__move_assign(list& __c, false_type) |
| 904 | { |
| 905 | if (base::__node_alloc() != __c.__node_alloc()) |
| 906 | { |
| 907 | typedef move_iterator<iterator> _I; |
| 908 | assign(_I(__c.begin()), _I(__c.end())); |
| 909 | } |
| 910 | else |
| 911 | __move_assign(__c, true_type()); |
| 912 | } |
| 913 | |
| 914 | template <class _Tp, class _Alloc> |
| 915 | void |
| 916 | list<_Tp, _Alloc>::__move_assign(list& __c, true_type) |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 917 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 918 | { |
| 919 | clear(); |
| 920 | base::__move_assign_alloc(__c); |
| 921 | splice(end(), __c); |
| 922 | } |
| 923 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 924 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | |
| 926 | template <class _Tp, class _Alloc> |
| 927 | template <class _InpIter> |
| 928 | void |
| 929 | list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, |
| 930 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 931 | { |
| 932 | iterator __i = begin(); |
| 933 | iterator __e = end(); |
| 934 | for (; __f != __l && __i != __e; ++__f, ++__i) |
| 935 | *__i = *__f; |
| 936 | if (__i == __e) |
| 937 | insert(__e, __f, __l); |
| 938 | else |
| 939 | erase(__i, __e); |
| 940 | } |
| 941 | |
| 942 | template <class _Tp, class _Alloc> |
| 943 | void |
| 944 | list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) |
| 945 | { |
| 946 | iterator __i = begin(); |
| 947 | iterator __e = end(); |
| 948 | for (; __n > 0 && __i != __e; --__n, ++__i) |
| 949 | *__i = __x; |
| 950 | if (__i == __e) |
| 951 | insert(__e, __n, __x); |
| 952 | else |
| 953 | erase(__i, __e); |
| 954 | } |
| 955 | |
| 956 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 957 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | _Alloc |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 959 | list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | { |
| 961 | return allocator_type(base::__node_alloc()); |
| 962 | } |
| 963 | |
| 964 | template <class _Tp, class _Alloc> |
| 965 | typename list<_Tp, _Alloc>::iterator |
| 966 | list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) |
| 967 | { |
| 968 | __node_allocator& __na = base::__node_alloc(); |
| 969 | typedef __allocator_destructor<__node_allocator> _D; |
| 970 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 971 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 972 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 974 | ++base::__sz(); |
| 975 | return iterator(__hold.release()); |
| 976 | } |
| 977 | |
| 978 | template <class _Tp, class _Alloc> |
| 979 | typename list<_Tp, _Alloc>::iterator |
| 980 | list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) |
| 981 | { |
| 982 | iterator __r(const_cast<__node_pointer>(__p.__ptr_)); |
| 983 | if (__n > 0) |
| 984 | { |
| 985 | size_type __ds = 0; |
| 986 | __node_allocator& __na = base::__node_alloc(); |
| 987 | typedef __allocator_destructor<__node_allocator> _D; |
| 988 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 989 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 990 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 991 | ++__ds; |
| 992 | __r = iterator(__hold.get()); |
| 993 | __hold.release(); |
| 994 | iterator __e = __r; |
| 995 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 996 | try |
| 997 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 998 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 999 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1000 | { |
| 1001 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1002 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | __e.__ptr_->__next_ = __hold.get(); |
| 1004 | __hold->__prev_ = __e.__ptr_; |
| 1005 | __hold.release(); |
| 1006 | } |
| 1007 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1008 | } |
| 1009 | catch (...) |
| 1010 | { |
| 1011 | while (true) |
| 1012 | { |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1013 | __node_alloc_traits::destroy(__na, _STD::addressof(*__e)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1015 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1016 | if (__prev == 0) |
| 1017 | break; |
| 1018 | __e = iterator(__prev); |
| 1019 | } |
| 1020 | throw; |
| 1021 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1022 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); |
| 1024 | base::__sz() += __ds; |
| 1025 | } |
| 1026 | return __r; |
| 1027 | } |
| 1028 | |
| 1029 | template <class _Tp, class _Alloc> |
| 1030 | template <class _InpIter> |
| 1031 | typename list<_Tp, _Alloc>::iterator |
| 1032 | list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 1033 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 1034 | { |
| 1035 | iterator __r(const_cast<__node_pointer>(__p.__ptr_)); |
| 1036 | if (__f != __l) |
| 1037 | { |
| 1038 | size_type __ds = 0; |
| 1039 | __node_allocator& __na = base::__node_alloc(); |
| 1040 | typedef __allocator_destructor<__node_allocator> _D; |
| 1041 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1042 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1043 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), *__f); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | ++__ds; |
| 1045 | __r = iterator(__hold.get()); |
| 1046 | __hold.release(); |
| 1047 | iterator __e = __r; |
| 1048 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1049 | try |
| 1050 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1051 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1052 | for (++__f; __f != __l; ++__f, ++__e, ++__ds) |
| 1053 | { |
| 1054 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1055 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), *__f); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | __e.__ptr_->__next_ = __hold.get(); |
| 1057 | __hold->__prev_ = __e.__ptr_; |
| 1058 | __hold.release(); |
| 1059 | } |
| 1060 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1061 | } |
| 1062 | catch (...) |
| 1063 | { |
| 1064 | while (true) |
| 1065 | { |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1066 | __node_alloc_traits::destroy(__na, _STD::addressof(*__e)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1068 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1069 | if (__prev == 0) |
| 1070 | break; |
| 1071 | __e = iterator(__prev); |
| 1072 | } |
| 1073 | throw; |
| 1074 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1075 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); |
| 1077 | base::__sz() += __ds; |
| 1078 | } |
| 1079 | return __r; |
| 1080 | } |
| 1081 | |
| 1082 | template <class _Tp, class _Alloc> |
| 1083 | void |
| 1084 | list<_Tp, _Alloc>::push_front(const value_type& __x) |
| 1085 | { |
| 1086 | __node_allocator& __na = base::__node_alloc(); |
| 1087 | typedef __allocator_destructor<__node_allocator> _D; |
| 1088 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1089 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1091 | ++base::__sz(); |
| 1092 | __hold.release(); |
| 1093 | } |
| 1094 | |
| 1095 | template <class _Tp, class _Alloc> |
| 1096 | void |
| 1097 | list<_Tp, _Alloc>::push_back(const value_type& __x) |
| 1098 | { |
| 1099 | __node_allocator& __na = base::__node_alloc(); |
| 1100 | typedef __allocator_destructor<__node_allocator> _D; |
| 1101 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1102 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1103 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1104 | ++base::__sz(); |
| 1105 | __hold.release(); |
| 1106 | } |
| 1107 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1108 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1109 | |
| 1110 | template <class _Tp, class _Alloc> |
| 1111 | void |
| 1112 | list<_Tp, _Alloc>::push_front(value_type&& __x) |
| 1113 | { |
| 1114 | __node_allocator& __na = base::__node_alloc(); |
| 1115 | typedef __allocator_destructor<__node_allocator> _D; |
| 1116 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1117 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1119 | ++base::__sz(); |
| 1120 | __hold.release(); |
| 1121 | } |
| 1122 | |
| 1123 | template <class _Tp, class _Alloc> |
| 1124 | void |
| 1125 | list<_Tp, _Alloc>::push_back(value_type&& __x) |
| 1126 | { |
| 1127 | __node_allocator& __na = base::__node_alloc(); |
| 1128 | typedef __allocator_destructor<__node_allocator> _D; |
| 1129 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1130 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1131 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1132 | ++base::__sz(); |
| 1133 | __hold.release(); |
| 1134 | } |
| 1135 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1136 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1137 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | template <class _Tp, class _Alloc> |
| 1139 | template <class... _Args> |
| 1140 | void |
| 1141 | list<_Tp, _Alloc>::emplace_front(_Args&&... __args) |
| 1142 | { |
| 1143 | __node_allocator& __na = base::__node_alloc(); |
| 1144 | typedef __allocator_destructor<__node_allocator> _D; |
| 1145 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1146 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1147 | __link_nodes(*base::__end_.__next_, *__hold, *__hold); |
| 1148 | ++base::__sz(); |
| 1149 | __hold.release(); |
| 1150 | } |
| 1151 | |
| 1152 | template <class _Tp, class _Alloc> |
| 1153 | template <class... _Args> |
| 1154 | void |
| 1155 | list<_Tp, _Alloc>::emplace_back(_Args&&... __args) |
| 1156 | { |
| 1157 | __node_allocator& __na = base::__node_alloc(); |
| 1158 | typedef __allocator_destructor<__node_allocator> _D; |
| 1159 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1160 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1161 | __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); |
| 1162 | ++base::__sz(); |
| 1163 | __hold.release(); |
| 1164 | } |
| 1165 | |
| 1166 | template <class _Tp, class _Alloc> |
| 1167 | template <class... _Args> |
| 1168 | typename list<_Tp, _Alloc>::iterator |
| 1169 | list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) |
| 1170 | { |
| 1171 | __node_allocator& __na = base::__node_alloc(); |
| 1172 | typedef __allocator_destructor<__node_allocator> _D; |
| 1173 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1174 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1175 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 1177 | ++base::__sz(); |
| 1178 | return iterator(__hold.release()); |
| 1179 | } |
| 1180 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1181 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1182 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | template <class _Tp, class _Alloc> |
| 1184 | typename list<_Tp, _Alloc>::iterator |
| 1185 | list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) |
| 1186 | { |
| 1187 | __node_allocator& __na = base::__node_alloc(); |
| 1188 | typedef __allocator_destructor<__node_allocator> _D; |
| 1189 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1190 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1191 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), _STD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); |
| 1193 | ++base::__sz(); |
| 1194 | return iterator(__hold.release()); |
| 1195 | } |
| 1196 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1197 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | |
| 1199 | template <class _Tp, class _Alloc> |
| 1200 | void |
| 1201 | list<_Tp, _Alloc>::pop_front() |
| 1202 | { |
| 1203 | __node_allocator& __na = base::__node_alloc(); |
| 1204 | __node& __n = *base::__end_.__next_; |
| 1205 | base::__unlink_nodes(__n, __n); |
| 1206 | --base::__sz(); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1207 | __node_alloc_traits::destroy(__na, _STD::addressof(__n.__value_)); |
| 1208 | __node_alloc_traits::deallocate(__na, _STD::addressof(__n), 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | template <class _Tp, class _Alloc> |
| 1212 | void |
| 1213 | list<_Tp, _Alloc>::pop_back() |
| 1214 | { |
| 1215 | __node_allocator& __na = base::__node_alloc(); |
| 1216 | __node& __n = *base::__end_.__prev_; |
| 1217 | base::__unlink_nodes(__n, __n); |
| 1218 | --base::__sz(); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1219 | __node_alloc_traits::destroy(__na, _STD::addressof(__n.__value_)); |
| 1220 | __node_alloc_traits::deallocate(__na, _STD::addressof(__n), 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | template <class _Tp, class _Alloc> |
| 1224 | typename list<_Tp, _Alloc>::iterator |
| 1225 | list<_Tp, _Alloc>::erase(const_iterator __p) |
| 1226 | { |
| 1227 | __node_allocator& __na = base::__node_alloc(); |
| 1228 | __node& __n = const_cast<__node&>(*__p.__ptr_); |
| 1229 | __node_pointer __r = __n.__next_; |
| 1230 | base::__unlink_nodes(__n, __n); |
| 1231 | --base::__sz(); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1232 | __node_alloc_traits::destroy(__na, _STD::addressof(__n.__value_)); |
| 1233 | __node_alloc_traits::deallocate(__na, _STD::addressof(__n), 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | return iterator(__r); |
| 1235 | } |
| 1236 | |
| 1237 | template <class _Tp, class _Alloc> |
| 1238 | typename list<_Tp, _Alloc>::iterator |
| 1239 | list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) |
| 1240 | { |
| 1241 | if (__f != __l) |
| 1242 | { |
| 1243 | __node_allocator& __na = base::__node_alloc(); |
| 1244 | base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_); |
| 1245 | while (__f != __l) |
| 1246 | { |
| 1247 | __node& __n = const_cast<__node&>(*__f.__ptr_); |
| 1248 | ++__f; |
| 1249 | --base::__sz(); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1250 | __node_alloc_traits::destroy(__na, _STD::addressof(__n.__value_)); |
| 1251 | __node_alloc_traits::deallocate(__na, _STD::addressof(__n), 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
| 1254 | return iterator(const_cast<__node_pointer>(__l.__ptr_)); |
| 1255 | } |
| 1256 | |
| 1257 | template <class _Tp, class _Alloc> |
| 1258 | void |
| 1259 | list<_Tp, _Alloc>::resize(size_type __n) |
| 1260 | { |
| 1261 | if (__n < base::__sz()) |
| 1262 | erase(__iterator(__n), end()); |
| 1263 | else if (__n > base::__sz()) |
| 1264 | { |
| 1265 | __n -= base::__sz(); |
| 1266 | size_type __ds = 0; |
| 1267 | __node_allocator& __na = base::__node_alloc(); |
| 1268 | typedef __allocator_destructor<__node_allocator> _D; |
| 1269 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1270 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1271 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1272 | ++__ds; |
| 1273 | iterator __r = iterator(__hold.release()); |
| 1274 | iterator __e = __r; |
| 1275 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1276 | try |
| 1277 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1278 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1279 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1280 | { |
| 1281 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1282 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1283 | __e.__ptr_->__next_ = __hold.get(); |
| 1284 | __hold->__prev_ = __e.__ptr_; |
| 1285 | __hold.release(); |
| 1286 | } |
| 1287 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1288 | } |
| 1289 | catch (...) |
| 1290 | { |
| 1291 | while (true) |
| 1292 | { |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1293 | __node_alloc_traits::destroy(__na, _STD::addressof(*__e)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1294 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1295 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1296 | if (__prev == 0) |
| 1297 | break; |
| 1298 | __e = iterator(__prev); |
| 1299 | } |
| 1300 | throw; |
| 1301 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1302 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); |
| 1304 | base::__sz() += __ds; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | template <class _Tp, class _Alloc> |
| 1309 | void |
| 1310 | list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) |
| 1311 | { |
| 1312 | if (__n < base::__sz()) |
| 1313 | erase(__iterator(__n), end()); |
| 1314 | else if (__n > base::__sz()) |
| 1315 | { |
| 1316 | __n -= base::__sz(); |
| 1317 | size_type __ds = 0; |
| 1318 | __node_allocator& __na = base::__node_alloc(); |
| 1319 | typedef __allocator_destructor<__node_allocator> _D; |
| 1320 | unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1)); |
| 1321 | __hold->__prev_ = 0; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1322 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 | ++__ds; |
| 1324 | iterator __r = iterator(__hold.release()); |
| 1325 | iterator __e = __r; |
| 1326 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1327 | try |
| 1328 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1329 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1330 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1331 | { |
| 1332 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1333 | __node_alloc_traits::construct(__na, _STD::addressof(__hold->__value_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | __e.__ptr_->__next_ = __hold.get(); |
| 1335 | __hold->__prev_ = __e.__ptr_; |
| 1336 | __hold.release(); |
| 1337 | } |
| 1338 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1339 | } |
| 1340 | catch (...) |
| 1341 | { |
| 1342 | while (true) |
| 1343 | { |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1344 | __node_alloc_traits::destroy(__na, _STD::addressof(*__e)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | __node_pointer __prev = __e.__ptr_->__prev_; |
| 1346 | __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); |
| 1347 | if (__prev == 0) |
| 1348 | break; |
| 1349 | __e = iterator(__prev); |
| 1350 | } |
| 1351 | throw; |
| 1352 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1353 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); |
| 1355 | base::__sz() += __ds; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1356 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | template <class _Tp, class _Alloc> |
| 1360 | void |
| 1361 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) |
| 1362 | { |
| 1363 | if (!__c.empty()) |
| 1364 | { |
| 1365 | __node& __f = *__c.__end_.__next_; |
| 1366 | __node& __l = *__c.__end_.__prev_; |
| 1367 | base::__unlink_nodes(__f, __l); |
| 1368 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l); |
| 1369 | base::__sz() += __c.__sz(); |
| 1370 | __c.__sz() = 0; |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | template <class _Tp, class _Alloc> |
| 1375 | void |
| 1376 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) |
| 1377 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1378 | if (__p != __i && __p != _STD::next(__i)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1379 | { |
| 1380 | __node& __f = const_cast<__node&>(*__i.__ptr_); |
| 1381 | base::__unlink_nodes(__f, __f); |
| 1382 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f); |
| 1383 | --__c.__sz(); |
| 1384 | ++base::__sz(); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | template <class _Tp, class _Alloc> |
| 1389 | void |
| 1390 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) |
| 1391 | { |
| 1392 | if (__f != __l) |
| 1393 | { |
| 1394 | if (this != &__c) |
| 1395 | { |
| 1396 | size_type __s = _STD::distance(__f, __l); |
| 1397 | __c.__sz() -= __s; |
| 1398 | base::__sz() += __s; |
| 1399 | } |
| 1400 | __node& __first = const_cast<__node&>(*__f.__ptr_); |
| 1401 | --__l; |
| 1402 | __node& __last = const_cast<__node&>(*__l.__ptr_); |
| 1403 | base::__unlink_nodes(__first, __last); |
| 1404 | __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | template <class _Tp, class _Alloc> |
| 1409 | void |
| 1410 | list<_Tp, _Alloc>::remove(const value_type& __x) |
| 1411 | { |
| 1412 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1413 | { |
| 1414 | if (*__i == __x) |
| 1415 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1416 | iterator __j = _STD::next(__i); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1417 | for (; __j != __e && *__j == __x; ++__j) |
| 1418 | ; |
| 1419 | __i = erase(__i, __j); |
| 1420 | } |
| 1421 | else |
| 1422 | ++__i; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | template <class _Tp, class _Alloc> |
| 1427 | template <class _Pred> |
| 1428 | void |
| 1429 | list<_Tp, _Alloc>::remove_if(_Pred __pred) |
| 1430 | { |
| 1431 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1432 | { |
| 1433 | if (__pred(*__i)) |
| 1434 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1435 | iterator __j = _STD::next(__i); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | for (; __j != __e && __pred(*__j); ++__j) |
| 1437 | ; |
| 1438 | __i = erase(__i, __j); |
| 1439 | } |
| 1440 | else |
| 1441 | ++__i; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1446 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1447 | void |
| 1448 | list<_Tp, _Alloc>::unique() |
| 1449 | { |
| 1450 | unique(__equal_to<value_type>()); |
| 1451 | } |
| 1452 | |
| 1453 | template <class _Tp, class _Alloc> |
| 1454 | template <class _BinaryPred> |
| 1455 | void |
| 1456 | list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) |
| 1457 | { |
| 1458 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1459 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1460 | iterator __j = _STD::next(__i); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | for (; __j != __e && __binary_pred(*__i, *__j); ++__j) |
| 1462 | ; |
| 1463 | if (++__i != __j) |
| 1464 | __i = erase(__i, __j); |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1469 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | void |
| 1471 | list<_Tp, _Alloc>::merge(list& __c) |
| 1472 | { |
| 1473 | merge(__c, __less<value_type>()); |
| 1474 | } |
| 1475 | |
| 1476 | template <class _Tp, class _Alloc> |
| 1477 | template <class _Comp> |
| 1478 | void |
| 1479 | list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) |
| 1480 | { |
| 1481 | if (this != &__c) |
| 1482 | { |
| 1483 | iterator __f1 = begin(); |
| 1484 | iterator __e1 = end(); |
| 1485 | iterator __f2 = __c.begin(); |
| 1486 | iterator __e2 = __c.end(); |
| 1487 | while (__f1 != __e1 && __f2 != __e2) |
| 1488 | { |
| 1489 | if (__comp(*__f2, *__f1)) |
| 1490 | { |
| 1491 | size_type __ds = 1; |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1492 | iterator __m2 = _STD::next(__f2); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1493 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) |
| 1494 | ; |
| 1495 | base::__sz() += __ds; |
| 1496 | __c.__sz() -= __ds; |
| 1497 | __node& __f = *__f2.__ptr_; |
| 1498 | __node& __l = *__m2.__ptr_->__prev_; |
| 1499 | __f2 = __m2; |
| 1500 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1501 | __m2 = _STD::next(__f1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1502 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1503 | __f1 = __m2; |
| 1504 | } |
| 1505 | else |
| 1506 | ++__f1; |
| 1507 | } |
| 1508 | splice(__e1, __c); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1513 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1514 | void |
| 1515 | list<_Tp, _Alloc>::sort() |
| 1516 | { |
| 1517 | sort(__less<value_type>()); |
| 1518 | } |
| 1519 | |
| 1520 | template <class _Tp, class _Alloc> |
| 1521 | template <class _Comp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1522 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | void |
| 1524 | list<_Tp, _Alloc>::sort(_Comp __comp) |
| 1525 | { |
| 1526 | __sort(begin(), end(), base::__sz(), __comp); |
| 1527 | } |
| 1528 | |
| 1529 | template <class _Tp, class _Alloc> |
| 1530 | template <class _Comp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1531 | typename list<_Tp, _Alloc>::iterator |
| 1532 | list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) |
| 1533 | { |
| 1534 | switch (__n) |
| 1535 | { |
| 1536 | case 0: |
| 1537 | case 1: |
| 1538 | return __f1; |
| 1539 | case 2: |
| 1540 | if (__comp(*--__e2, *__f1)) |
| 1541 | { |
| 1542 | __node& __f = *__e2.__ptr_; |
| 1543 | base::__unlink_nodes(__f, __f); |
| 1544 | __link_nodes(*__f1.__ptr_, __f, __f); |
| 1545 | return __e2; |
| 1546 | } |
| 1547 | return __f1; |
| 1548 | } |
| 1549 | size_type __n2 = __n / 2; |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1550 | iterator __e1 = _STD::next(__f1, __n2); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); |
| 1552 | iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); |
| 1553 | if (__comp(*__f2, *__f1)) |
| 1554 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1555 | iterator __m2 = _STD::next(__f2); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 1557 | ; |
| 1558 | __node& __f = *__f2.__ptr_; |
| 1559 | __node& __l = *__m2.__ptr_->__prev_; |
| 1560 | __r = __f2; |
| 1561 | __e1 = __f2 = __m2; |
| 1562 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1563 | __m2 = _STD::next(__f1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1564 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1565 | __f1 = __m2; |
| 1566 | } |
| 1567 | else |
| 1568 | ++__f1; |
| 1569 | while (__f1 != __e1 && __f2 != __e2) |
| 1570 | { |
| 1571 | if (__comp(*__f2, *__f1)) |
| 1572 | { |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1573 | iterator __m2 = _STD::next(__f2); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1574 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 1575 | ; |
| 1576 | __node& __f = *__f2.__ptr_; |
| 1577 | __node& __l = *__m2.__ptr_->__prev_; |
| 1578 | if (__e1 == __f2) |
| 1579 | __e1 = __m2; |
| 1580 | __f2 = __m2; |
| 1581 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1582 | __m2 = _STD::next(__f1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1583 | __link_nodes(*__f1.__ptr_, __f, __l); |
| 1584 | __f1 = __m2; |
| 1585 | } |
| 1586 | else |
| 1587 | ++__f1; |
| 1588 | } |
| 1589 | return __r; |
| 1590 | } |
| 1591 | |
| 1592 | template <class _Tp, class _Alloc> |
| 1593 | void |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1594 | list<_Tp, _Alloc>::reverse() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1595 | { |
| 1596 | if (base::__sz() > 1) |
| 1597 | { |
| 1598 | iterator __e = end(); |
| 1599 | for (iterator __i = begin(); __i != __e; --__i) |
| 1600 | _STD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); |
| 1601 | _STD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1606 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | bool |
| 1608 | operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1609 | { |
| 1610 | return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin()); |
| 1611 | } |
| 1612 | |
| 1613 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1614 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | bool |
| 1616 | operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1617 | { |
| 1618 | return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 1619 | } |
| 1620 | |
| 1621 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1622 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1623 | bool |
| 1624 | operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1625 | { |
| 1626 | return !(__x == __y); |
| 1627 | } |
| 1628 | |
| 1629 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1630 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1631 | bool |
| 1632 | operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1633 | { |
| 1634 | return __y < __x; |
| 1635 | } |
| 1636 | |
| 1637 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1638 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | bool |
| 1640 | operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1641 | { |
| 1642 | return !(__x < __y); |
| 1643 | } |
| 1644 | |
| 1645 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1646 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | bool |
| 1648 | operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1649 | { |
| 1650 | return !(__y < __x); |
| 1651 | } |
| 1652 | |
| 1653 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1654 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | void |
| 1656 | swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) |
Howard Hinnant | c560727 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1657 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | { |
| 1659 | __x.swap(__y); |
| 1660 | } |
| 1661 | |
| 1662 | _LIBCPP_END_NAMESPACE_STD |
| 1663 | |
| 1664 | #endif // _LIBCPP_LIST |