struct _Fwd_list_node_base
{
_Fwd_list_node_base() = default;
+ _Fwd_list_node_base(_Fwd_list_node_base&& __x) noexcept
+ : _M_next(__x._M_next)
+ { __x._M_next = nullptr; }
+
+ _Fwd_list_node_base(const _Fwd_list_node_base&) = delete;
+ _Fwd_list_node_base& operator=(const _Fwd_list_node_base&) = delete;
+
+ _Fwd_list_node_base&
+ operator=(_Fwd_list_node_base&& __x) noexcept
+ {
+ _M_next = __x._M_next;
+ __x._M_next = nullptr;
+ return *this;
+ }
_Fwd_list_node_base* _M_next = nullptr;
__end->_M_next = _M_next;
}
else
- __begin->_M_next = 0;
+ __begin->_M_next = nullptr;
_M_next = __keep;
return __end;
}
/**
* @brief A forward_list::iterator.
- *
+ *
* All the functions are op overloads.
*/
template<typename _Tp>
struct _Fwd_list_iterator
{
- typedef _Fwd_list_iterator<_Tp> _Self;
- typedef _Fwd_list_node<_Tp> _Node;
+ typedef _Fwd_list_iterator<_Tp> _Self;
+ typedef _Fwd_list_node<_Tp> _Node;
- typedef _Tp value_type;
- typedef _Tp* pointer;
- typedef _Tp& reference;
- typedef ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+ typedef ptrdiff_t difference_type;
+ typedef std::forward_iterator_tag iterator_category;
_Fwd_list_iterator() noexcept
: _M_node() { }
_Self&
operator++() noexcept
{
- _M_node = _M_node->_M_next;
- return *this;
+ _M_node = _M_node->_M_next;
+ return *this;
}
_Self
operator++(int) noexcept
{
- _Self __tmp(*this);
- _M_node = _M_node->_M_next;
- return __tmp;
+ _Self __tmp(*this);
+ _M_node = _M_node->_M_next;
+ return __tmp;
}
bool
_Self
_M_next() const noexcept
{
- if (_M_node)
- return _Fwd_list_iterator(_M_node->_M_next);
- else
- return _Fwd_list_iterator(0);
+ if (_M_node)
+ return _Fwd_list_iterator(_M_node->_M_next);
+ else
+ return _Fwd_list_iterator(nullptr);
}
_Fwd_list_node_base* _M_node;
/**
* @brief A forward_list::const_iterator.
- *
+ *
* All the functions are op overloads.
*/
template<typename _Tp>
struct _Fwd_list_const_iterator
{
- typedef _Fwd_list_const_iterator<_Tp> _Self;
- typedef const _Fwd_list_node<_Tp> _Node;
- typedef _Fwd_list_iterator<_Tp> iterator;
+ typedef _Fwd_list_const_iterator<_Tp> _Self;
+ typedef const _Fwd_list_node<_Tp> _Node;
+ typedef _Fwd_list_iterator<_Tp> iterator;
- typedef _Tp value_type;
- typedef const _Tp* pointer;
- typedef const _Tp& reference;
- typedef ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef const _Tp* pointer;
+ typedef const _Tp& reference;
+ typedef ptrdiff_t difference_type;
+ typedef std::forward_iterator_tag iterator_category;
_Fwd_list_const_iterator() noexcept
: _M_node() { }
_Self&
operator++() noexcept
{
- _M_node = _M_node->_M_next;
- return *this;
+ _M_node = _M_node->_M_next;
+ return *this;
}
_Self
operator++(int) noexcept
{
- _Self __tmp(*this);
- _M_node = _M_node->_M_next;
- return __tmp;
+ _Self __tmp(*this);
+ _M_node = _M_node->_M_next;
+ return __tmp;
}
bool
_Self
_M_next() const noexcept
{
- if (this->_M_node)
- return _Fwd_list_const_iterator(_M_node->_M_next);
- else
- return _Fwd_list_const_iterator(0);
+ if (this->_M_node)
+ return _Fwd_list_const_iterator(_M_node->_M_next);
+ else
+ return _Fwd_list_const_iterator(nullptr);
}
const _Fwd_list_node_base* _M_node;
template<typename _Tp>
inline bool
operator==(const _Fwd_list_iterator<_Tp>& __x,
- const _Fwd_list_const_iterator<_Tp>& __y) noexcept
+ const _Fwd_list_const_iterator<_Tp>& __y) noexcept
{ return __x._M_node == __y._M_node; }
/**
template<typename _Tp>
inline bool
operator!=(const _Fwd_list_iterator<_Tp>& __x,
- const _Fwd_list_const_iterator<_Tp>& __y) noexcept
+ const _Fwd_list_const_iterator<_Tp>& __y) noexcept
{ return __x._M_node != __y._M_node; }
/**
typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
- struct _Fwd_list_impl
+ struct _Fwd_list_impl
: public _Node_alloc_type
{
- _Fwd_list_node_base _M_head;
+ _Fwd_list_node_base _M_head;
+
+ _Fwd_list_impl()
+ noexcept( noexcept(_Node_alloc_type()) )
+ : _Node_alloc_type(), _M_head()
+ { }
- _Fwd_list_impl()
- : _Node_alloc_type(), _M_head()
- { }
+ _Fwd_list_impl(_Fwd_list_impl&&) = default;
- _Fwd_list_impl(const _Node_alloc_type& __a)
- : _Node_alloc_type(__a), _M_head()
- { }
+ _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
+ : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
+ { }
- _Fwd_list_impl(_Node_alloc_type&& __a)
+ _Fwd_list_impl(_Node_alloc_type&& __a)
: _Node_alloc_type(std::move(__a)), _M_head()
- { }
+ { }
};
_Fwd_list_impl _M_impl;
public:
- typedef _Fwd_list_iterator<_Tp> iterator;
- typedef _Fwd_list_const_iterator<_Tp> const_iterator;
- typedef _Fwd_list_node<_Tp> _Node;
+ typedef _Fwd_list_iterator<_Tp> iterator;
+ typedef _Fwd_list_const_iterator<_Tp> const_iterator;
+ typedef _Fwd_list_node<_Tp> _Node;
_Node_alloc_type&
_M_get_Node_allocator() noexcept
_M_get_Node_allocator() const noexcept
{ return this->_M_impl; }
- _Fwd_list_base()
- : _M_impl() { }
+ _Fwd_list_base() = default;
_Fwd_list_base(_Node_alloc_type&& __a)
: _M_impl(std::move(__a)) { }
+ // When allocators are always equal.
+ _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a,
+ std::true_type)
+ : _M_impl(std::move(__lst._M_impl), std::move(__a))
+ { }
+
+ // When allocators are not always equal.
_Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a);
- _Fwd_list_base(_Fwd_list_base&& __lst)
- : _M_impl(std::move(__lst._M_get_Node_allocator()))
- {
- this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
- __lst._M_impl._M_head._M_next = 0;
- }
+ _Fwd_list_base(_Fwd_list_base&&) = default;
~_Fwd_list_base()
- { _M_erase_after(&_M_impl._M_head, 0); }
+ { _M_erase_after(&_M_impl._M_head, nullptr); }
protected:
-
_Node*
_M_get_node()
{
}
template<typename... _Args>
- _Node*
- _M_create_node(_Args&&... __args)
- {
- _Node* __node = this->_M_get_node();
- __try
- {
+ _Node*
+ _M_create_node(_Args&&... __args)
+ {
+ _Node* __node = this->_M_get_node();
+ __try
+ {
_Tp_alloc_type __a(_M_get_Node_allocator());
typedef allocator_traits<_Tp_alloc_type> _Alloc_traits;
::new ((void*)__node) _Node;
_Alloc_traits::construct(__a, __node->_M_valptr(),
std::forward<_Args>(__args)...);
- }
- __catch(...)
- {
- this->_M_put_node(__node);
- __throw_exception_again;
- }
- return __node;
- }
+ }
+ __catch(...)
+ {
+ this->_M_put_node(__node);
+ __throw_exception_again;
+ }
+ return __node;
+ }
template<typename... _Args>
- _Fwd_list_node_base*
- _M_insert_after(const_iterator __pos, _Args&&... __args);
+ _Fwd_list_node_base*
+ _M_insert_after(const_iterator __pos, _Args&&... __args);
void
_M_put_node(_Node* __p)
_M_erase_after(_Fwd_list_node_base* __pos);
_Fwd_list_node_base*
- _M_erase_after(_Fwd_list_node_base* __pos,
- _Fwd_list_node_base* __last);
+ _M_erase_after(_Fwd_list_node_base* __pos,
+ _Fwd_list_node_base* __last);
};
/**
#endif
private:
- typedef _Fwd_list_base<_Tp, _Alloc> _Base;
- typedef _Fwd_list_node<_Tp> _Node;
- typedef _Fwd_list_node_base _Node_base;
- typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
- typedef typename _Base::_Node_alloc_type _Node_alloc_type;
- typedef typename _Base::_Node_alloc_traits _Node_alloc_traits;
- typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits;
+ typedef _Fwd_list_base<_Tp, _Alloc> _Base;
+ typedef _Fwd_list_node<_Tp> _Node;
+ typedef _Fwd_list_node_base _Node_base;
+ typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
+ typedef typename _Base::_Node_alloc_type _Node_alloc_type;
+ typedef typename _Base::_Node_alloc_traits _Node_alloc_traits;
+ typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits;
public:
// types:
- typedef _Tp value_type;
- typedef typename _Alloc_traits::pointer pointer;
- typedef typename _Alloc_traits::const_pointer const_pointer;
- typedef value_type& reference;
- typedef const value_type& const_reference;
-
- typedef _Fwd_list_iterator<_Tp> iterator;
- typedef _Fwd_list_const_iterator<_Tp> const_iterator;
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
- typedef _Alloc allocator_type;
+ typedef _Tp value_type;
+ typedef typename _Alloc_traits::pointer pointer;
+ typedef typename _Alloc_traits::const_pointer const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+
+ typedef _Fwd_list_iterator<_Tp> iterator;
+ typedef _Fwd_list_const_iterator<_Tp> const_iterator;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef _Alloc allocator_type;
// 23.3.4.2 construct/copy/destroy:
/**
* @brief Creates a %forward_list with no elements.
*/
- forward_list()
- noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
- : _Base()
- { }
+ forward_list() = default;
/**
* @brief Creates a %forward_list with no elements.
: _Base(_Node_alloc_type(__al))
{ }
-
/**
* @brief Copy constructor with allocator argument.
* @param __list Input list to copy.
: _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__list.begin(), __list.end()); }
- /**
- * @brief Move constructor with allocator argument.
- * @param __list Input list to move.
- * @param __al An allocator object.
- */
- forward_list(forward_list&& __list, const _Alloc& __al)
- noexcept(_Node_alloc_traits::_S_always_equal())
- : _Base(std::move(__list), _Node_alloc_type(__al))
+ private:
+ forward_list(forward_list&& __list, _Node_alloc_type&& __al,
+ false_type)
+ : _Base(std::move(__list), std::move(__al))
{
// If __list is not empty it means its allocator is not equal to __a,
// so we need to move from each element individually.
std::__make_move_if_noexcept_iterator(__list.end()));
}
+ forward_list(forward_list&& __list, _Node_alloc_type&& __al,
+ true_type)
+ noexcept
+ : _Base(std::move(__list), _Node_alloc_type(__al), true_type{})
+ { }
+
+ public:
+ /**
+ * @brief Move constructor with allocator argument.
+ * @param __list Input list to move.
+ * @param __al An allocator object.
+ */
+ forward_list(forward_list&& __list, const _Alloc& __al)
+ noexcept(_Node_alloc_traits::_S_always_equal())
+ : forward_list(std::move(__list), _Node_alloc_type(__al),
+ typename _Node_alloc_traits::is_always_equal{})
+ { }
+
/**
* @brief Creates a %forward_list with default constructed elements.
* @param __n The number of elements to initially create.
* @a __value.
*/
forward_list(size_type __n, const _Tp& __value,
- const _Alloc& __al = _Alloc())
+ const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al))
{ _M_fill_initialize(__n, __value); }
*/
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
- forward_list(_InputIterator __first, _InputIterator __last,
- const _Alloc& __al = _Alloc())
+ forward_list(_InputIterator __first, _InputIterator __last,
+ const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al))
- { _M_range_initialize(__first, __last); }
+ { _M_range_initialize(__first, __last); }
/**
* @brief The %forward_list copy constructor.
*/
forward_list(const forward_list& __list)
: _Base(_Node_alloc_traits::_S_select_on_copy(
- __list._M_get_Node_allocator()))
+ __list._M_get_Node_allocator()))
{ _M_range_initialize(__list.begin(), __list.end()); }
/**
* @param __list A %forward_list of identical element and allocator
* types.
*
- * The newly-created %forward_list contains the exact contents of @a
- * __list. The contents of @a __list are a valid, but unspecified
- * %forward_list.
+ * The newly-created %forward_list contains the exact contents of the
+ * moved instance. The contents of the moved instance are a valid, but
+ * unspecified %forward_list.
*/
- forward_list(forward_list&& __list) noexcept
- : _Base(std::move(__list)) { }
+ forward_list(forward_list&&) = default;
/**
* @brief Builds a %forward_list from an initializer_list
* in the initializer_list @a __il. This is linear in __il.size().
*/
forward_list(std::initializer_list<_Tp> __il,
- const _Alloc& __al = _Alloc())
+ const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__il.begin(), __il.end()); }
operator=(forward_list&& __list)
noexcept(_Node_alloc_traits::_S_nothrow_move())
{
- constexpr bool __move_storage =
- _Node_alloc_traits::_S_propagate_on_move_assign()
- || _Node_alloc_traits::_S_always_equal();
- _M_move_assign(std::move(__list), __bool_constant<__move_storage>());
+ constexpr bool __move_storage =
+ _Node_alloc_traits::_S_propagate_on_move_assign()
+ || _Node_alloc_traits::_S_always_equal();
+ _M_move_assign(std::move(__list), __bool_constant<__move_storage>());
return *this;
}
forward_list&
operator=(std::initializer_list<_Tp> __il)
{
- assign(__il);
- return *this;
+ assign(__il);
+ return *this;
}
/**
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
void
- assign(_InputIterator __first, _InputIterator __last)
- {
+ assign(_InputIterator __first, _InputIterator __last)
+ {
typedef is_assignable<_Tp, decltype(*__first)> __assignable;
_M_assign(__first, __last, __assignable());
}
*/
iterator
end() noexcept
- { return iterator(0); }
+ { return iterator(nullptr); }
/**
* Returns a read-only iterator that points one past the last
*/
const_iterator
end() const noexcept
- { return const_iterator(0); }
+ { return const_iterator(nullptr); }
/**
* Returns a read-only (constant) iterator that points to the
*/
const_iterator
cend() const noexcept
- { return const_iterator(0); }
+ { return const_iterator(nullptr); }
/**
* Returns true if the %forward_list is empty. (Thus begin() would
*/
bool
empty() const noexcept
- { return this->_M_impl._M_head._M_next == 0; }
+ { return this->_M_impl._M_head._M_next == nullptr; }
/**
* Returns the largest possible number of elements of %forward_list.
reference
front()
{
- _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
- return *__front->_M_valptr();
+ _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
+ return *__front->_M_valptr();
}
/**
const_reference
front() const
{
- _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
- return *__front->_M_valptr();
+ _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
+ return *__front->_M_valptr();
}
// 23.3.4.5 modifiers:
*/
template<typename... _Args>
#if __cplusplus > 201402L
- reference
+ reference
#else
void
#endif
- emplace_front(_Args&&... __args)
- {
+ emplace_front(_Args&&... __args)
+ {
this->_M_insert_after(cbefore_begin(),
- std::forward<_Args>(__args)...);
+ std::forward<_Args>(__args)...);
#if __cplusplus > 201402L
return front();
#endif
* and references.
*/
template<typename... _Args>
- iterator
- emplace_after(const_iterator __pos, _Args&&... __args)
- { return iterator(this->_M_insert_after(__pos,
- std::forward<_Args>(__args)...)); }
+ iterator
+ emplace_after(const_iterator __pos, _Args&&... __args)
+ { return iterator(this->_M_insert_after(__pos,
+ std::forward<_Args>(__args)...)); }
/**
* @brief Inserts given value into %forward_list after specified
*/
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
- iterator
- insert_after(const_iterator __pos,
- _InputIterator __first, _InputIterator __last);
+ iterator
+ insert_after(const_iterator __pos,
+ _InputIterator __first, _InputIterator __last);
/**
* @brief Inserts the contents of an initializer_list into
void
swap(forward_list& __list) noexcept
{
- std::swap(this->_M_impl._M_head._M_next,
+ std::swap(this->_M_impl._M_head._M_next,
__list._M_impl._M_head._M_next);
_Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
- __list._M_get_Node_allocator());
+ __list._M_get_Node_allocator());
}
/**
*/
void
clear() noexcept
- { this->_M_erase_after(&this->_M_impl._M_head, 0); }
+ { this->_M_erase_after(&this->_M_impl._M_head, nullptr); }
// 23.3.4.6 forward_list operations:
*/
void
splice_after(const_iterator __pos, forward_list&& __list,
- const_iterator __i) noexcept;
+ const_iterator __i) noexcept;
void
splice_after(const_iterator __pos, forward_list& __list,
- const_iterator __i) noexcept
+ const_iterator __i) noexcept
{ splice_after(__pos, std::move(__list), __i); }
/**
*/
void
splice_after(const_iterator __pos, forward_list&&,
- const_iterator __before, const_iterator __last) noexcept
+ const_iterator __before, const_iterator __last) noexcept
{ _M_splice_after(__pos, __before, __last); }
void
splice_after(const_iterator __pos, forward_list&,
- const_iterator __before, const_iterator __last) noexcept
+ const_iterator __before, const_iterator __last) noexcept
{ _M_splice_after(__pos, __before, __last); }
// @}
* responsibility.
*/
template<typename _Pred>
- void
- remove_if(_Pred __pred);
+ void
+ remove_if(_Pred __pred);
/**
* @brief Remove consecutive duplicate elements.
* Managing the pointer is the user's responsibility.
*/
template<typename _BinPred>
- void
- unique(_BinPred __binary_pred);
+ void
+ unique(_BinPred __binary_pred);
/**
* @brief Merge sorted lists.
* according to comp().
*/
template<typename _Comp>
- void
- merge(forward_list&& __list, _Comp __comp);
+ void
+ merge(forward_list&& __list, _Comp __comp);
template<typename _Comp>
- void
- merge(forward_list& __list, _Comp __comp)
- { merge(std::move(__list), __comp); }
+ void
+ merge(forward_list& __list, _Comp __comp)
+ { merge(std::move(__list), __comp); }
/**
* @brief Sort the elements of the list.
* elements remain in list order.
*/
template<typename _Comp>
- void
- sort(_Comp __comp);
+ void
+ sort(_Comp __comp);
/**
* @brief Reverse the elements in list.
private:
// Called by the range constructor to implement [23.3.4.2]/9
template<typename _InputIterator>
- void
- _M_range_initialize(_InputIterator __first, _InputIterator __last);
+ void
+ _M_range_initialize(_InputIterator __first, _InputIterator __last);
// Called by forward_list(n,v,a), and the range constructor when it
// turns out to be the same thing.
// Called by operator=(forward_list&&)
void
- _M_move_assign(forward_list&& __list, std::true_type) noexcept
+ _M_move_assign(forward_list&& __list, true_type) noexcept
{
- clear();
- this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
- __list._M_impl._M_head._M_next = nullptr;
- std::__alloc_on_move(this->_M_get_Node_allocator(),
- __list._M_get_Node_allocator());
+ clear();
+ this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
+ __list._M_impl._M_head._M_next = nullptr;
+ std::__alloc_on_move(this->_M_get_Node_allocator(),
+ __list._M_get_Node_allocator());
}
// Called by operator=(forward_list&&)
void
- _M_move_assign(forward_list&& __list, std::false_type)
+ _M_move_assign(forward_list&& __list, false_type)
{
- if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
- _M_move_assign(std::move(__list), std::true_type());
- else
+ if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
+ _M_move_assign(std::move(__list), true_type());
+ else
// The rvalue's allocator cannot be moved, or is not equal,
// so we need to individually move each element.
this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
// CopyAssignable.
template<typename _InputIterator>
void
- _M_assign(_InputIterator __first, _InputIterator __last, true_type)
+ _M_assign(_InputIterator __first, _InputIterator __last, true_type)
{
auto __prev = before_begin();
auto __curr = begin();
insert_after(__prev, __first, __last);
else if (__curr != __end)
erase_after(__prev, __end);
- }
+ }
// Called by assign(_InputIterator, _InputIterator) if _Tp is not
// CopyAssignable.
template<typename _InputIterator>
void
- _M_assign(_InputIterator __first, _InputIterator __last, false_type)
+ _M_assign(_InputIterator __first, _InputIterator __last, false_type)
{
clear();
insert_after(cbefore_begin(), __first, __last);
* @param __ly A %forward_list of the same type as @a __lx.
* @return True iff the elements of the forward lists are equal.
*
- * This is an equivalence relation. It is linear in the number of
+ * This is an equivalence relation. It is linear in the number of
* elements of the forward lists. Deques are considered equivalent
* if corresponding elements compare equal.
*/
template<typename _Tp, typename _Alloc>
bool
operator==(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly);
+ const forward_list<_Tp, _Alloc>& __ly);
/**
* @brief Forward list ordering relation.
* @param __ly A %forward_list of the same type as @a __lx.
* @return True iff @a __lx is lexicographically less than @a __ly.
*
- * This is a total ordering relation. It is linear in the number of
+ * This is a total ordering relation. It is linear in the number of
* elements of the forward lists. The elements must be comparable
* with @c <.
*
template<typename _Tp, typename _Alloc>
inline bool
operator<(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{ return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
__ly.cbegin(), __ly.cend()); }
template<typename _Tp, typename _Alloc>
inline bool
operator!=(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{ return !(__lx == __ly); }
/// Based on operator<
template<typename _Tp, typename _Alloc>
inline bool
operator>(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{ return (__ly < __lx); }
/// Based on operator<
template<typename _Tp, typename _Alloc>
inline bool
operator>=(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{ return !(__lx < __ly); }
/// Based on operator<
template<typename _Tp, typename _Alloc>
inline bool
operator<=(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{ return !(__ly < __lx); }
/// See std::forward_list::swap().
: _M_impl(std::move(__a))
{
if (__lst._M_get_Node_allocator() == _M_get_Node_allocator())
- {
- this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
- __lst._M_impl._M_head._M_next = 0;
- }
- else
- this->_M_impl._M_head._M_next = 0;
+ this->_M_impl._M_head = std::move(__lst._M_impl._M_head);
}
template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>::
_M_insert_after(const_iterator __pos, _Args&&... __args)
{
- _Fwd_list_node_base* __to
+ _Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
- __thing->_M_next = __to->_M_next;
- __to->_M_next = __thing;
- return __to->_M_next;
+ __thing->_M_next = __to->_M_next;
+ __to->_M_next = __thing;
+ return __to->_M_next;
}
template<typename _Tp, typename _Alloc>
template<typename _Tp, typename _Alloc>
_Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>::
- _M_erase_after(_Fwd_list_node_base* __pos,
- _Fwd_list_node_base* __last)
+ _M_erase_after(_Fwd_list_node_base* __pos,
+ _Fwd_list_node_base* __last)
{
_Node* __curr = static_cast<_Node*>(__pos->_M_next);
while (__curr != __last)
- {
- _Node* __temp = __curr;
- __curr = static_cast<_Node*>(__curr->_M_next);
+ {
+ _Node* __temp = __curr;
+ __curr = static_cast<_Node*>(__curr->_M_next);
_Tp_alloc_type __a(_M_get_Node_allocator());
allocator_traits<_Tp_alloc_type>::destroy(__a, __temp->_M_valptr());
__temp->~_Node();
- _M_put_node(__temp);
- }
+ _M_put_node(__temp);
+ }
__pos->_M_next = __last;
return __last;
}
forward_list<_Tp, _Alloc>::
_M_range_initialize(_InputIterator __first, _InputIterator __last)
{
- _Node_base* __to = &this->_M_impl._M_head;
- for (; __first != __last; ++__first)
- {
- __to->_M_next = this->_M_create_node(*__first);
- __to = __to->_M_next;
- }
+ _Node_base* __to = &this->_M_impl._M_head;
+ for (; __first != __last; ++__first)
+ {
+ __to->_M_next = this->_M_create_node(*__first);
+ __to = __to->_M_next;
+ }
}
// Called by forward_list(n,v,a).
{
_Node_base* __to = &this->_M_impl._M_head;
for (; __n; --__n)
- {
- __to->_M_next = this->_M_create_node(__value);
- __to = __to->_M_next;
- }
+ {
+ __to->_M_next = this->_M_create_node(__value);
+ __to = __to->_M_next;
+ }
}
template<typename _Tp, typename _Alloc>
{
_Node_base* __to = &this->_M_impl._M_head;
for (; __n; --__n)
- {
- __to->_M_next = this->_M_create_node();
- __to = __to->_M_next;
- }
+ {
+ __to->_M_next = this->_M_create_node();
+ __to = __to->_M_next;
+ }
}
template<typename _Tp, typename _Alloc>
operator=(const forward_list& __list)
{
if (std::__addressof(__list) != this)
- {
+ {
if (_Node_alloc_traits::_S_propagate_on_copy_assign())
{
- auto& __this_alloc = this->_M_get_Node_allocator();
- auto& __that_alloc = __list._M_get_Node_allocator();
- if (!_Node_alloc_traits::_S_always_equal()
- && __this_alloc != __that_alloc)
- {
+ auto& __this_alloc = this->_M_get_Node_allocator();
+ auto& __that_alloc = __list._M_get_Node_allocator();
+ if (!_Node_alloc_traits::_S_always_equal()
+ && __this_alloc != __that_alloc)
+ {
// replacement allocator cannot free existing storage
clear();
}
std::__alloc_on_copy(__this_alloc, __that_alloc);
- }
+ }
assign(__list.cbegin(), __list.cend());
- }
+ }
return *this;
}
size_type __len = 0;
while (__k._M_next() != end() && __len < __sz)
- {
- ++__k;
- ++__len;
- }
+ {
+ ++__k;
+ ++__len;
+ }
if (__len == __sz)
- erase_after(__k, end());
+ erase_after(__k, end());
else
_M_default_insert_after(__k, __sz - __len);
}
size_type __len = 0;
while (__k._M_next() != end() && __len < __sz)
- {
- ++__k;
- ++__len;
- }
+ {
+ ++__k;
+ ++__len;
+ }
if (__len == __sz)
- erase_after(__k, end());
+ erase_after(__k, end());
else
- insert_after(__k, __sz - __len, __val);
+ insert_after(__k, __sz - __len, __val);
}
template<typename _Tp, typename _Alloc>
__end = __end->_M_next;
if (__b != __end)
- return iterator(__tmp->_M_transfer_after(__b, __end));
+ return iterator(__tmp->_M_transfer_after(__b, __end));
else
return iterator(__tmp);
}
_Node_base* __extra = nullptr;
while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
- {
- if (*__tmp->_M_valptr() == __val)
+ {
+ if (*__tmp->_M_valptr() == __val)
{
if (__tmp->_M_valptr() != std::__addressof(__val))
{
__extra = __curr;
}
__curr = __curr->_M_next;
- }
+ }
if (__extra)
this->_M_erase_after(__extra);
remove_if(_Pred __pred)
{
_Node_base* __curr = &this->_M_impl._M_head;
- while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
- {
- if (__pred(*__tmp->_M_valptr()))
- this->_M_erase_after(__curr);
- else
- __curr = __curr->_M_next;
- }
+ while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
+ {
+ if (__pred(*__tmp->_M_valptr()))
+ this->_M_erase_after(__curr);
+ else
+ __curr = __curr->_M_next;
+ }
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
unique(_BinPred __binary_pred)
{
- iterator __first = begin();
- iterator __last = end();
- if (__first == __last)
- return;
- iterator __next = __first;
- while (++__next != __last)
- {
- if (__binary_pred(*__first, *__next))
- erase_after(__first);
- else
- __first = __next;
- __next = __first;
- }
+ iterator __first = begin();
+ iterator __last = end();
+ if (__first == __last)
+ return;
+ iterator __next = __first;
+ while (++__next != __last)
+ {
+ if (__binary_pred(*__first, *__next))
+ erase_after(__first);
+ else
+ __first = __next;
+ __next = __first;
+ }
}
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>::
merge(forward_list&& __list, _Comp __comp)
{
- _Node_base* __node = &this->_M_impl._M_head;
- while (__node->_M_next && __list._M_impl._M_head._M_next)
- {
- if (__comp(*static_cast<_Node*>
- (__list._M_impl._M_head._M_next)->_M_valptr(),
- *static_cast<_Node*>
- (__node->_M_next)->_M_valptr()))
- __node->_M_transfer_after(&__list._M_impl._M_head,
- __list._M_impl._M_head._M_next);
- __node = __node->_M_next;
- }
- if (__list._M_impl._M_head._M_next)
- {
- __node->_M_next = __list._M_impl._M_head._M_next;
- __list._M_impl._M_head._M_next = 0;
- }
+ _Node_base* __node = &this->_M_impl._M_head;
+ while (__node->_M_next && __list._M_impl._M_head._M_next)
+ {
+ if (__comp(*static_cast<_Node*>
+ (__list._M_impl._M_head._M_next)->_M_valptr(),
+ *static_cast<_Node*>
+ (__node->_M_next)->_M_valptr()))
+ __node->_M_transfer_after(&__list._M_impl._M_head,
+ __list._M_impl._M_head._M_next);
+ __node = __node->_M_next;
+ }
+
+ if (__list._M_impl._M_head._M_next)
+ *__node = std::move(__list._M_impl._M_head);
}
template<typename _Tp, typename _Alloc>
bool
operator==(const forward_list<_Tp, _Alloc>& __lx,
- const forward_list<_Tp, _Alloc>& __ly)
+ const forward_list<_Tp, _Alloc>& __ly)
{
// We don't have size() so we need to walk through both lists
// making sure both iterators are valid.
auto __ix = __lx.cbegin();
auto __iy = __ly.cbegin();
while (__ix != __lx.cend() && __iy != __ly.cend())
- {
- if (*__ix != *__iy)
- return false;
- ++__ix;
- ++__iy;
- }
+ {
+ if (*__ix != *__iy)
+ return false;
+ ++__ix;
+ ++__iy;
+ }
if (__ix == __lx.cend() && __iy == __ly.cend())
- return true;
+ return true;
else
- return false;
+ return false;
}
template<typename _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::
sort(_Comp __comp)
{
- // If `next' is 0, return immediately.
- _Node* __list = static_cast<_Node*>(this->_M_impl._M_head._M_next);
- if (!__list)
- return;
-
- unsigned long __insize = 1;
-
- while (1)
- {
- _Node* __p = __list;
- __list = 0;
- _Node* __tail = 0;
-
- // Count number of merges we do in this pass.
- unsigned long __nmerges = 0;
-
- while (__p)
- {
- ++__nmerges;
- // There exists a merge to be done.
- // Step `insize' places along from p.
- _Node* __q = __p;
- unsigned long __psize = 0;
- for (unsigned long __i = 0; __i < __insize; ++__i)
- {
- ++__psize;
- __q = static_cast<_Node*>(__q->_M_next);
- if (!__q)
- break;
- }
-
- // If q hasn't fallen off end, we have two lists to merge.
- unsigned long __qsize = __insize;
-
- // Now we have two lists; merge them.
- while (__psize > 0 || (__qsize > 0 && __q))
- {
- // Decide whether next node of merge comes from p or q.
- _Node* __e;
- if (__psize == 0)
- {
- // p is empty; e must come from q.
- __e = __q;
- __q = static_cast<_Node*>(__q->_M_next);
- --__qsize;
- }
- else if (__qsize == 0 || !__q)
- {
- // q is empty; e must come from p.
- __e = __p;
- __p = static_cast<_Node*>(__p->_M_next);
- --__psize;
- }
- else if (__comp(*__p->_M_valptr(), *__q->_M_valptr()))
- {
- // First node of p is lower; e must come from p.
- __e = __p;
- __p = static_cast<_Node*>(__p->_M_next);
- --__psize;
- }
- else
- {
- // First node of q is lower; e must come from q.
- __e = __q;
- __q = static_cast<_Node*>(__q->_M_next);
- --__qsize;
- }
-
- // Add the next node to the merged list.
- if (__tail)
- __tail->_M_next = __e;
- else
- __list = __e;
- __tail = __e;
- }
-
- // Now p has stepped `insize' places along, and q has too.
- __p = __q;
- }
- __tail->_M_next = 0;
-
- // If we have done only one merge, we're finished.
- // Allow for nmerges == 0, the empty list case.
- if (__nmerges <= 1)
- {
- this->_M_impl._M_head._M_next = __list;
- return;
- }
-
- // Otherwise repeat, merging lists twice the size.
- __insize *= 2;
- }
+ // If `next' is nullptr, return immediately.
+ _Node* __list = static_cast<_Node*>(this->_M_impl._M_head._M_next);
+ if (!__list)
+ return;
+
+ unsigned long __insize = 1;
+
+ while (1)
+ {
+ _Node* __p = __list;
+ __list = nullptr;
+ _Node* __tail = nullptr;
+
+ // Count number of merges we do in this pass.
+ unsigned long __nmerges = 0;
+
+ while (__p)
+ {
+ ++__nmerges;
+ // There exists a merge to be done.
+ // Step `insize' places along from p.
+ _Node* __q = __p;
+ unsigned long __psize = 0;
+ for (unsigned long __i = 0; __i < __insize; ++__i)
+ {
+ ++__psize;
+ __q = static_cast<_Node*>(__q->_M_next);
+ if (!__q)
+ break;
+ }
+
+ // If q hasn't fallen off end, we have two lists to merge.
+ unsigned long __qsize = __insize;
+
+ // Now we have two lists; merge them.
+ while (__psize > 0 || (__qsize > 0 && __q))
+ {
+ // Decide whether next node of merge comes from p or q.
+ _Node* __e;
+ if (__psize == 0)
+ {
+ // p is empty; e must come from q.
+ __e = __q;
+ __q = static_cast<_Node*>(__q->_M_next);
+ --__qsize;
+ }
+ else if (__qsize == 0 || !__q)
+ {
+ // q is empty; e must come from p.
+ __e = __p;
+ __p = static_cast<_Node*>(__p->_M_next);
+ --__psize;
+ }
+ else if (__comp(*__p->_M_valptr(), *__q->_M_valptr()))
+ {
+ // First node of p is lower; e must come from p.
+ __e = __p;
+ __p = static_cast<_Node*>(__p->_M_next);
+ --__psize;
+ }
+ else
+ {
+ // First node of q is lower; e must come from q.
+ __e = __q;
+ __q = static_cast<_Node*>(__q->_M_next);
+ --__qsize;
+ }
+
+ // Add the next node to the merged list.
+ if (__tail)
+ __tail->_M_next = __e;
+ else
+ __list = __e;
+ __tail = __e;
+ }
+
+ // Now p has stepped `insize' places along, and q has too.
+ __p = __q;
+ }
+ __tail->_M_next = nullptr;
+
+ // If we have done only one merge, we're finished.
+ // Allow for nmerges == 0, the empty list case.
+ if (__nmerges <= 1)
+ {
+ this->_M_impl._M_head._M_next = __list;
+ return;
+ }
+
+ // Otherwise repeat, merging lists twice the size.
+ __insize *= 2;
+ }
}
-
+
_GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif /* _FORWARD_LIST_TCC */
-