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