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