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