30 #ifndef _FORWARD_LIST_H 31 #define _FORWARD_LIST_H 1 33 #pragma GCC system_header 44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
58 : _M_next(__x._M_next)
59 { __x._M_next =
nullptr; }
67 _M_next = __x._M_next;
68 __x._M_next =
nullptr;
81 __begin->_M_next = __end->_M_next;
82 __end->_M_next = _M_next;
85 __begin->_M_next =
nullptr;
91 _M_reverse_after() noexcept
100 __tail->_M_next = __temp->_M_next;
101 _M_next->_M_next = __keep;
112 template<
typename _Tp>
118 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
122 {
return _M_storage._M_ptr(); }
125 _M_valptr()
const noexcept
126 {
return _M_storage._M_ptr(); }
134 template<
typename _Tp>
140 typedef _Tp value_type;
141 typedef _Tp* pointer;
142 typedef _Tp& reference;
143 typedef ptrdiff_t difference_type;
154 operator*()
const noexcept
155 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
158 operator->()
const noexcept
159 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
162 operator++() noexcept
164 _M_node = _M_node->_M_next;
169 operator++(
int) noexcept
172 _M_node = _M_node->_M_next;
177 operator==(
const _Self& __x)
const noexcept
178 {
return _M_node == __x._M_node; }
181 operator!=(
const _Self& __x)
const noexcept
182 {
return _M_node != __x._M_node; }
185 _M_next()
const noexcept
201 template<
typename _Tp>
208 typedef _Tp value_type;
209 typedef const _Tp* pointer;
210 typedef const _Tp& reference;
211 typedef ptrdiff_t difference_type;
222 : _M_node(__iter._M_node) { }
225 operator*()
const noexcept
226 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
229 operator->()
const noexcept
230 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
233 operator++() noexcept
235 _M_node = _M_node->_M_next;
240 operator++(
int) noexcept
243 _M_node = _M_node->_M_next;
248 operator==(
const _Self& __x)
const noexcept
249 {
return _M_node == __x._M_node; }
252 operator!=(
const _Self& __x)
const noexcept
253 {
return _M_node != __x._M_node; }
256 _M_next()
const noexcept
270 template<
typename _Tp>
274 {
return __x._M_node == __y._M_node; }
279 template<
typename _Tp>
283 {
return __x._M_node != __y._M_node; }
288 template<
typename _Tp,
typename _Alloc>
292 typedef __alloc_rebind<_Alloc, _Tp> _Tp_alloc_type;
293 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
296 struct _Fwd_list_impl
297 :
public _Node_alloc_type
302 noexcept( noexcept(_Node_alloc_type()) )
303 : _Node_alloc_type(), _M_head()
306 _Fwd_list_impl(_Fwd_list_impl&&) =
default;
308 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
309 : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
312 _Fwd_list_impl(_Node_alloc_type&& __a)
313 : _Node_alloc_type(std::move(__a)), _M_head()
317 _Fwd_list_impl _M_impl;
325 _M_get_Node_allocator() noexcept
326 {
return this->_M_impl; }
328 const _Node_alloc_type&
329 _M_get_Node_allocator()
const noexcept
330 {
return this->_M_impl; }
335 : _M_impl(std::move(__a)) { }
340 : _M_impl(std::move(__lst._M_impl), std::move(__a))
349 { _M_erase_after(&_M_impl._M_head,
nullptr); }
356 return std::__to_address(__ptr);
359 template<
typename... _Args>
361 _M_create_node(_Args&&... __args)
363 _Node* __node = this->_M_get_node();
366 _Tp_alloc_type __a(_M_get_Node_allocator());
368 ::new ((
void*)__node)
_Node;
369 _Alloc_traits::construct(__a, __node->_M_valptr(),
370 std::forward<_Args>(__args)...);
374 this->_M_put_node(__node);
375 __throw_exception_again;
380 template<
typename... _Args>
385 _M_put_node(
_Node* __p)
387 typedef typename _Node_alloc_traits::pointer _Ptr;
426 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
429 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
430 "std::forward_list must have a non-const, non-volatile value_type");
431 #ifdef __STRICT_ANSI__ 433 "std::forward_list must have the same value_type as its allocator");
440 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
441 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
447 typedef _Tp value_type;
448 typedef typename _Alloc_traits::pointer pointer;
449 typedef typename _Alloc_traits::const_pointer const_pointer;
450 typedef value_type& reference;
451 typedef const value_type& const_reference;
455 typedef std::size_t size_type;
456 typedef std::ptrdiff_t difference_type;
457 typedef _Alloc allocator_type;
472 :
_Base(_Node_alloc_type(__al))
481 :
_Base(_Node_alloc_type(__al))
482 { _M_range_initialize(__list.
begin(), __list.
end()); }
487 : _Base(
std::move(__list),
std::move(__al))
492 std::__make_move_if_noexcept_iterator(__list.begin()),
493 std::__make_move_if_noexcept_iterator(__list.end()));
499 : _Base(std::move(__list), _Node_alloc_type(__al),
true_type{})
509 noexcept(_Node_alloc_traits::_S_always_equal())
524 :
_Base(_Node_alloc_type(__al))
525 { _M_default_initialize(__n); }
537 const _Alloc& __al = _Alloc())
538 :
_Base(_Node_alloc_type(__al))
539 { _M_fill_initialize(__n, __value); }
551 template<
typename _InputIterator,
552 typename = std::_RequireInputIter<_InputIterator>>
554 const _Alloc& __al = _Alloc())
555 :
_Base(_Node_alloc_type(__al))
556 { _M_range_initialize(__first, __last); }
565 __list._M_get_Node_allocator()))
566 { _M_range_initialize(__list.
begin(), __list.
end()); }
588 const _Alloc& __al = _Alloc())
589 :
_Base(_Node_alloc_type(__al))
590 { _M_range_initialize(__il.begin(), __il.end()); }
624 noexcept(_Node_alloc_traits::_S_nothrow_move())
626 constexpr
bool __move_storage =
627 _Node_alloc_traits::_S_propagate_on_move_assign()
628 || _Node_alloc_traits::_S_always_equal();
660 template<
typename _InputIterator,
661 typename = std::_RequireInputIter<_InputIterator>>
663 assign(_InputIterator __first, _InputIterator __last)
666 _M_assign(__first, __last, __assignable());
693 {
assign(__il.begin(), __il.end()); }
698 {
return allocator_type(this->_M_get_Node_allocator()); }
708 {
return iterator(&this->_M_impl._M_head); }
725 {
return iterator(this->_M_impl._M_head._M_next); }
787 {
return this->_M_impl._M_head._M_next ==
nullptr; }
805 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
806 return *__front->_M_valptr();
816 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
817 return *__front->_M_valptr();
833 template<
typename... _Args>
834 #if __cplusplus > 201402L 842 std::forward<_Args>(__args)...);
843 #if __cplusplus > 201402L 867 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
883 { this->_M_erase_after(&this->_M_impl._M_head); }
898 template<
typename... _Args>
901 {
return iterator(this->_M_insert_after(__pos,
902 std::forward<_Args>(__args)...)); }
918 {
return iterator(this->_M_insert_after(__pos, __val)); }
925 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
943 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
960 template<
typename _InputIterator,
961 typename = std::_RequireInputIter<_InputIterator>>
964 _InputIterator __first, _InputIterator __last);
983 {
return insert_after(__pos, __il.begin(), __il.end()); }
1004 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1005 (__pos._M_node))); }
1027 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1029 const_cast<_Node_base*>
1030 (__last._M_node))); }
1047 std::swap(this->_M_impl._M_head._M_next,
1048 __list._M_impl._M_head._M_next);
1049 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1050 __list._M_get_Node_allocator());
1080 resize(size_type __sz,
const value_type& __val);
1092 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1110 if (!__list.empty())
1111 _M_splice_after(__pos, __list.before_begin(), __list.end());
1130 const_iterator __i) noexcept;
1134 const_iterator __i) noexcept
1154 { _M_splice_after(__pos, __before, __last); }
1159 { _M_splice_after(__pos, __before, __last); }
1174 remove(
const _Tp& __val);
1187 template<
typename _Pred>
1217 template<
typename _BinPred>
1219 unique(_BinPred __binary_pred);
1236 {
merge(std::move(__list)); }
1249 template<
typename _Comp>
1253 template<
typename _Comp>
1256 {
merge(std::move(__list), __comp); }
1274 template<
typename _Comp>
1285 { this->_M_impl._M_head._M_reverse_after(); }
1289 template<
typename _InputIterator>
1291 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1296 _M_fill_initialize(size_type __n,
const value_type& __value);
1300 _M_splice_after(const_iterator __pos, const_iterator __before,
1301 const_iterator __last);
1305 _M_default_initialize(size_type __n);
1309 _M_default_insert_after(const_iterator __pos, size_type __n);
1316 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1317 __list._M_impl._M_head._M_next =
nullptr;
1318 std::__alloc_on_move(this->_M_get_Node_allocator(),
1319 __list._M_get_Node_allocator());
1326 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1327 _M_move_assign(std::move(__list),
true_type());
1331 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1332 std::__make_move_if_noexcept_iterator(__list.end()));
1337 template<
typename _InputIterator>
1339 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1342 auto __curr =
begin();
1344 while (__curr != __end && __first != __last)
1351 if (__first != __last)
1353 else if (__curr != __end)
1359 template<
typename _InputIterator>
1361 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1369 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1372 auto __curr =
begin();
1374 while (__curr != __end && __n > 0)
1383 else if (__curr != __end)
1389 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1396 #if __cpp_deduction_guides >= 201606 1397 template<
typename _InputIterator,
typename _ValT
1398 =
typename iterator_traits<_InputIterator>::value_type,
1399 typename _Allocator = allocator<_ValT>,
1400 typename = _RequireInputIter<_InputIterator>,
1401 typename = _RequireAllocator<_Allocator>>
1402 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1403 -> forward_list<_ValT, _Allocator>;
1416 template<
typename _Tp,
typename _Alloc>
1418 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1419 const forward_list<_Tp, _Alloc>& __ly);
1433 template<
typename _Tp,
typename _Alloc>
1435 operator<(const forward_list<_Tp, _Alloc>& __lx,
1438 __ly.cbegin(), __ly.cend()); }
1441 template<
typename _Tp,
typename _Alloc>
1445 {
return !(__lx == __ly); }
1448 template<
typename _Tp,
typename _Alloc>
1452 {
return (__ly < __lx); }
1455 template<
typename _Tp,
typename _Alloc>
1459 {
return !(__lx < __ly); }
1462 template<
typename _Tp,
typename _Alloc>
1464 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1466 {
return !(__ly < __lx); }
1469 template<
typename _Tp,
typename _Alloc>
1473 noexcept(noexcept(__lx.swap(__ly)))
1474 { __lx.swap(__ly); }
1476 _GLIBCXX_END_NAMESPACE_CONTAINER
1477 _GLIBCXX_END_NAMESPACE_VERSION
1480 #endif // _FORWARD_LIST_H
const_iterator cend() const noexcept
void unique()
Remove consecutive duplicate elements.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
size_type max_size() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
const_iterator cbefore_begin() const noexcept
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
iterator insert_after(const_iterator __pos, std::initializer_list< _Tp > __il)
Inserts the contents of an initializer_list into forward_list after the specified iterator...
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
void clear() noexcept
Erases all the elements.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
bool empty() const noexcept
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
iterator before_begin() noexcept
const_iterator cbegin() const noexcept
const_iterator before_begin() const noexcept
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
void pop_front()
Removes first element.
void swap(forward_list &__list) noexcept
Swaps data with another forward_list.
A forward_list::const_iterator.
forward_list()=default
Creates a forward_list with no elements.
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
One of the comparison functors.
const_reference front() const
void reverse() noexcept
Reverse the elements in list.
const_iterator begin() const noexcept
ISO C++ entities toplevel namespace is std.
One of the comparison functors.
Uniform interface to C++98 and C++11 allocators.
~forward_list() noexcept
The forward_list dtor.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
forward_list(const forward_list &__list)
The forward_list copy constructor.
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
void emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
void splice_after(const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
forward_list(forward_list &&__list, const _Alloc &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
A forward_list::iterator.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
void sort()
Sort the elements of the list.
void merge(forward_list &&__list)
Merge sorted lists.
const_iterator end() const noexcept
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
Forward iterators support a superset of input iterator operations.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
Base class for forward_list.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
Uniform interface to all pointer-like types.
iterator begin() noexcept
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.