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