Commit 75ce74bb by François Dumont

2018-01-10 François Dumont <fdumont@gcc.gnu.org>

	* include/bits/forward_list.h
	(_Fwd_list_node_base(_Fwd_list_node_base&&)): New.
	(_Fwd_list_node_base& operator=(_Fwd_list_node_base&&)): New.
	(_Fwd_list_node_base(const _Fwd_list_node_base&)): Explicit delete.
	(_Fwd_list_node_base& operator=(const _Fwd_list_node_base&)): Likewise.
	(_Fwd_list_impl()): Add noexcept qualification.
	(_Fwd_list_impl(const _Node_alloc_type&)): Delete.
	(_Fwd_list_impl(_Fwd_list_impl&&)): New, default.
	(_Fwd_list_impl(_Fwd_list_impl&&, _Node_alloc_type&&)): New.
	(_Fwd_list_base()): Default.
	(_Fwd_list_base(_Fwd_list_base&&, _Node_alloc_type&&, true_type)): New.
	(_Fwd_list_base(_Fwd_list_base&&)): Default.
	(forward_list<>()): Default.
	(forward_list<>(forward_list&&)): Default.
	(forward_list(forward_list&&, _Node_alloc_type&&, false_type)): New.
	(forward_list(forward_list&&, _Node_alloc_type&&, true_type)): New.
	(forward_list(forward_list&&, const _Alloc&)): Adapt to use latters.
	* include/bits/forward_list.tcc
	(_Fwd_list_base(_Fwd_list_base&&, _Node_alloc_type&&)): Adapt to use
	_M_impl._M_head move assignment.
	(forward_list<>::merge(forward_list<>&&, _Comp)): Likewise.
	* testsuite/23_containers/forward_list/allocator/default_init.cc: New.

From-SVN: r256439
parent 143aa5cc
2018-01-10 François Dumont <fdumont@gcc.gnu.org>
* include/bits/forward_list.h
(_Fwd_list_node_base(_Fwd_list_node_base&&)): New.
(_Fwd_list_node_base& operator=(_Fwd_list_node_base&&)): New.
(_Fwd_list_node_base(const _Fwd_list_node_base&)): Explicit delete.
(_Fwd_list_node_base& operator=(const _Fwd_list_node_base&)): Likewise.
(_Fwd_list_impl()): Add noexcept qualification.
(_Fwd_list_impl(const _Node_alloc_type&)): Delete.
(_Fwd_list_impl(_Fwd_list_impl&&)): New, default.
(_Fwd_list_impl(_Fwd_list_impl&&, _Node_alloc_type&&)): New.
(_Fwd_list_base()): Default.
(_Fwd_list_base(_Fwd_list_base&&, _Node_alloc_type&&, true_type)): New.
(_Fwd_list_base(_Fwd_list_base&&)): Default.
(forward_list<>()): Default.
(forward_list<>(forward_list&&)): Default.
(forward_list(forward_list&&, _Node_alloc_type&&, false_type)): New.
(forward_list(forward_list&&, _Node_alloc_type&&, true_type)): New.
(forward_list(forward_list&&, const _Alloc&)): Adapt to use latters.
* include/bits/forward_list.tcc
(_Fwd_list_base(_Fwd_list_base&&, _Node_alloc_type&&)): Adapt to use
_M_impl._M_head move assignment.
(forward_list<>::merge(forward_list<>&&, _Comp)): Likewise.
* testsuite/23_containers/forward_list/allocator/default_init.cc: New.
2018-01-09 Jonathan Wakely <jwakely@redhat.com> 2018-01-09 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/80276 PR libstdc++/80276
......
...@@ -54,6 +54,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -54,6 +54,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
struct _Fwd_list_node_base struct _Fwd_list_node_base
{ {
_Fwd_list_node_base() = default; _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; _Fwd_list_node_base* _M_next = nullptr;
...@@ -68,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -68,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
__end->_M_next = _M_next; __end->_M_next = _M_next;
} }
else else
__begin->_M_next = 0; __begin->_M_next = nullptr;
_M_next = __keep; _M_next = __keep;
return __end; return __end;
} }
...@@ -114,20 +128,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -114,20 +128,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/** /**
* @brief A forward_list::iterator. * @brief A forward_list::iterator.
* *
* All the functions are op overloads. * All the functions are op overloads.
*/ */
template<typename _Tp> template<typename _Tp>
struct _Fwd_list_iterator struct _Fwd_list_iterator
{ {
typedef _Fwd_list_iterator<_Tp> _Self; typedef _Fwd_list_iterator<_Tp> _Self;
typedef _Fwd_list_node<_Tp> _Node; typedef _Fwd_list_node<_Tp> _Node;
typedef _Tp value_type; typedef _Tp value_type;
typedef _Tp* pointer; typedef _Tp* pointer;
typedef _Tp& reference; typedef _Tp& reference;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category; typedef std::forward_iterator_tag iterator_category;
_Fwd_list_iterator() noexcept _Fwd_list_iterator() noexcept
: _M_node() { } : _M_node() { }
...@@ -147,16 +161,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -147,16 +161,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Self& _Self&
operator++() noexcept operator++() noexcept
{ {
_M_node = _M_node->_M_next; _M_node = _M_node->_M_next;
return *this; return *this;
} }
_Self _Self
operator++(int) noexcept operator++(int) noexcept
{ {
_Self __tmp(*this); _Self __tmp(*this);
_M_node = _M_node->_M_next; _M_node = _M_node->_M_next;
return __tmp; return __tmp;
} }
bool bool
...@@ -170,10 +184,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -170,10 +184,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Self _Self
_M_next() const noexcept _M_next() const noexcept
{ {
if (_M_node) if (_M_node)
return _Fwd_list_iterator(_M_node->_M_next); return _Fwd_list_iterator(_M_node->_M_next);
else else
return _Fwd_list_iterator(0); return _Fwd_list_iterator(nullptr);
} }
_Fwd_list_node_base* _M_node; _Fwd_list_node_base* _M_node;
...@@ -181,21 +195,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -181,21 +195,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/** /**
* @brief A forward_list::const_iterator. * @brief A forward_list::const_iterator.
* *
* All the functions are op overloads. * All the functions are op overloads.
*/ */
template<typename _Tp> template<typename _Tp>
struct _Fwd_list_const_iterator struct _Fwd_list_const_iterator
{ {
typedef _Fwd_list_const_iterator<_Tp> _Self; typedef _Fwd_list_const_iterator<_Tp> _Self;
typedef const _Fwd_list_node<_Tp> _Node; typedef const _Fwd_list_node<_Tp> _Node;
typedef _Fwd_list_iterator<_Tp> iterator; typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Tp value_type; typedef _Tp value_type;
typedef const _Tp* pointer; typedef const _Tp* pointer;
typedef const _Tp& reference; typedef const _Tp& reference;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category; typedef std::forward_iterator_tag iterator_category;
_Fwd_list_const_iterator() noexcept _Fwd_list_const_iterator() noexcept
: _M_node() { } : _M_node() { }
...@@ -218,16 +232,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -218,16 +232,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Self& _Self&
operator++() noexcept operator++() noexcept
{ {
_M_node = _M_node->_M_next; _M_node = _M_node->_M_next;
return *this; return *this;
} }
_Self _Self
operator++(int) noexcept operator++(int) noexcept
{ {
_Self __tmp(*this); _Self __tmp(*this);
_M_node = _M_node->_M_next; _M_node = _M_node->_M_next;
return __tmp; return __tmp;
} }
bool bool
...@@ -241,10 +255,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -241,10 +255,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Self _Self
_M_next() const noexcept _M_next() const noexcept
{ {
if (this->_M_node) if (this->_M_node)
return _Fwd_list_const_iterator(_M_node->_M_next); return _Fwd_list_const_iterator(_M_node->_M_next);
else else
return _Fwd_list_const_iterator(0); return _Fwd_list_const_iterator(nullptr);
} }
const _Fwd_list_node_base* _M_node; const _Fwd_list_node_base* _M_node;
...@@ -256,7 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -256,7 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp> template<typename _Tp>
inline bool inline bool
operator==(const _Fwd_list_iterator<_Tp>& __x, 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; } { return __x._M_node == __y._M_node; }
/** /**
...@@ -265,7 +279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -265,7 +279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp> template<typename _Tp>
inline bool inline bool
operator!=(const _Fwd_list_iterator<_Tp>& __x, 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; } { return __x._M_node != __y._M_node; }
/** /**
...@@ -279,30 +293,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -279,30 +293,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type; typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits; typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
struct _Fwd_list_impl struct _Fwd_list_impl
: public _Node_alloc_type : 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() _Fwd_list_impl(_Fwd_list_impl&&) = default;
: _Node_alloc_type(), _M_head()
{ }
_Fwd_list_impl(const _Node_alloc_type& __a) _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
: _Node_alloc_type(__a), _M_head() : _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() : _Node_alloc_type(std::move(__a)), _M_head()
{ } { }
}; };
_Fwd_list_impl _M_impl; _Fwd_list_impl _M_impl;
public: public:
typedef _Fwd_list_iterator<_Tp> iterator; typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Fwd_list_const_iterator<_Tp> const_iterator; typedef _Fwd_list_const_iterator<_Tp> const_iterator;
typedef _Fwd_list_node<_Tp> _Node; typedef _Fwd_list_node<_Tp> _Node;
_Node_alloc_type& _Node_alloc_type&
_M_get_Node_allocator() noexcept _M_get_Node_allocator() noexcept
...@@ -312,26 +329,26 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -312,26 +329,26 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_M_get_Node_allocator() const noexcept _M_get_Node_allocator() const noexcept
{ return this->_M_impl; } { return this->_M_impl; }
_Fwd_list_base() _Fwd_list_base() = default;
: _M_impl() { }
_Fwd_list_base(_Node_alloc_type&& __a) _Fwd_list_base(_Node_alloc_type&& __a)
: _M_impl(std::move(__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, _Node_alloc_type&& __a);
_Fwd_list_base(_Fwd_list_base&& __lst) _Fwd_list_base(_Fwd_list_base&&) = default;
: _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()
{ _M_erase_after(&_M_impl._M_head, 0); } { _M_erase_after(&_M_impl._M_head, nullptr); }
protected: protected:
_Node* _Node*
_M_get_node() _M_get_node()
{ {
...@@ -340,29 +357,29 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -340,29 +357,29 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
} }
template<typename... _Args> template<typename... _Args>
_Node* _Node*
_M_create_node(_Args&&... __args) _M_create_node(_Args&&... __args)
{ {
_Node* __node = this->_M_get_node(); _Node* __node = this->_M_get_node();
__try __try
{ {
_Tp_alloc_type __a(_M_get_Node_allocator()); _Tp_alloc_type __a(_M_get_Node_allocator());
typedef allocator_traits<_Tp_alloc_type> _Alloc_traits; typedef allocator_traits<_Tp_alloc_type> _Alloc_traits;
::new ((void*)__node) _Node; ::new ((void*)__node) _Node;
_Alloc_traits::construct(__a, __node->_M_valptr(), _Alloc_traits::construct(__a, __node->_M_valptr(),
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
} }
__catch(...) __catch(...)
{ {
this->_M_put_node(__node); this->_M_put_node(__node);
__throw_exception_again; __throw_exception_again;
} }
return __node; return __node;
} }
template<typename... _Args> template<typename... _Args>
_Fwd_list_node_base* _Fwd_list_node_base*
_M_insert_after(const_iterator __pos, _Args&&... __args); _M_insert_after(const_iterator __pos, _Args&&... __args);
void void
_M_put_node(_Node* __p) _M_put_node(_Node* __p)
...@@ -376,8 +393,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -376,8 +393,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_M_erase_after(_Fwd_list_node_base* __pos); _M_erase_after(_Fwd_list_node_base* __pos);
_Fwd_list_node_base* _Fwd_list_node_base*
_M_erase_after(_Fwd_list_node_base* __pos, _M_erase_after(_Fwd_list_node_base* __pos,
_Fwd_list_node_base* __last); _Fwd_list_node_base* __last);
}; };
/** /**
...@@ -417,37 +434,34 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -417,37 +434,34 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#endif #endif
private: private:
typedef _Fwd_list_base<_Tp, _Alloc> _Base; typedef _Fwd_list_base<_Tp, _Alloc> _Base;
typedef _Fwd_list_node<_Tp> _Node; typedef _Fwd_list_node<_Tp> _Node;
typedef _Fwd_list_node_base _Node_base; typedef _Fwd_list_node_base _Node_base;
typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
typedef typename _Base::_Node_alloc_type _Node_alloc_type; typedef typename _Base::_Node_alloc_type _Node_alloc_type;
typedef typename _Base::_Node_alloc_traits _Node_alloc_traits; typedef typename _Base::_Node_alloc_traits _Node_alloc_traits;
typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits; typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits;
public: public:
// types: // types:
typedef _Tp value_type; typedef _Tp value_type;
typedef typename _Alloc_traits::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Alloc_traits::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef value_type& reference; typedef value_type& reference;
typedef const value_type& const_reference; typedef const value_type& const_reference;
typedef _Fwd_list_iterator<_Tp> iterator; typedef _Fwd_list_iterator<_Tp> iterator;
typedef _Fwd_list_const_iterator<_Tp> const_iterator; typedef _Fwd_list_const_iterator<_Tp> const_iterator;
typedef std::size_t size_type; typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
// 23.3.4.2 construct/copy/destroy: // 23.3.4.2 construct/copy/destroy:
/** /**
* @brief Creates a %forward_list with no elements. * @brief Creates a %forward_list with no elements.
*/ */
forward_list() forward_list() = default;
noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
: _Base()
{ }
/** /**
* @brief Creates a %forward_list with no elements. * @brief Creates a %forward_list with no elements.
...@@ -458,7 +472,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -458,7 +472,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _Base(_Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ } { }
/** /**
* @brief Copy constructor with allocator argument. * @brief Copy constructor with allocator argument.
* @param __list Input list to copy. * @param __list Input list to copy.
...@@ -468,14 +481,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -468,14 +481,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _Base(_Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__list.begin(), __list.end()); } { _M_range_initialize(__list.begin(), __list.end()); }
/** private:
* @brief Move constructor with allocator argument. forward_list(forward_list&& __list, _Node_alloc_type&& __al,
* @param __list Input list to move. false_type)
* @param __al An allocator object. : _Base(std::move(__list), std::move(__al))
*/
forward_list(forward_list&& __list, const _Alloc& __al)
noexcept(_Node_alloc_traits::_S_always_equal())
: _Base(std::move(__list), _Node_alloc_type(__al))
{ {
// If __list is not empty it means its allocator is not equal to __a, // If __list is not empty it means its allocator is not equal to __a,
// so we need to move from each element individually. // so we need to move from each element individually.
...@@ -484,6 +493,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -484,6 +493,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
std::__make_move_if_noexcept_iterator(__list.end())); 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. * @brief Creates a %forward_list with default constructed elements.
* @param __n The number of elements to initially create. * @param __n The number of elements to initially create.
...@@ -507,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -507,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @a __value. * @a __value.
*/ */
forward_list(size_type __n, const _Tp& __value, forward_list(size_type __n, const _Tp& __value,
const _Alloc& __al = _Alloc()) const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ _M_fill_initialize(__n, __value); } { _M_fill_initialize(__n, __value); }
...@@ -523,10 +550,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -523,10 +550,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
template<typename _InputIterator, template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>> typename = std::_RequireInputIter<_InputIterator>>
forward_list(_InputIterator __first, _InputIterator __last, forward_list(_InputIterator __first, _InputIterator __last,
const _Alloc& __al = _Alloc()) const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__first, __last); } { _M_range_initialize(__first, __last); }
/** /**
* @brief The %forward_list copy constructor. * @brief The %forward_list copy constructor.
...@@ -535,7 +562,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -535,7 +562,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
forward_list(const forward_list& __list) forward_list(const forward_list& __list)
: _Base(_Node_alloc_traits::_S_select_on_copy( : _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()); } { _M_range_initialize(__list.begin(), __list.end()); }
/** /**
...@@ -543,12 +570,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -543,12 +570,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @param __list A %forward_list of identical element and allocator * @param __list A %forward_list of identical element and allocator
* types. * types.
* *
* The newly-created %forward_list contains the exact contents of @a * The newly-created %forward_list contains the exact contents of the
* __list. The contents of @a __list are a valid, but unspecified * moved instance. The contents of the moved instance are a valid, but
* %forward_list. * unspecified %forward_list.
*/ */
forward_list(forward_list&& __list) noexcept forward_list(forward_list&&) = default;
: _Base(std::move(__list)) { }
/** /**
* @brief Builds a %forward_list from an initializer_list * @brief Builds a %forward_list from an initializer_list
...@@ -559,7 +585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -559,7 +585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* in the initializer_list @a __il. This is linear in __il.size(). * in the initializer_list @a __il. This is linear in __il.size().
*/ */
forward_list(std::initializer_list<_Tp> __il, forward_list(std::initializer_list<_Tp> __il,
const _Alloc& __al = _Alloc()) const _Alloc& __al = _Alloc())
: _Base(_Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__il.begin(), __il.end()); } { _M_range_initialize(__il.begin(), __il.end()); }
...@@ -597,10 +623,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -597,10 +623,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
operator=(forward_list&& __list) operator=(forward_list&& __list)
noexcept(_Node_alloc_traits::_S_nothrow_move()) noexcept(_Node_alloc_traits::_S_nothrow_move())
{ {
constexpr bool __move_storage = constexpr bool __move_storage =
_Node_alloc_traits::_S_propagate_on_move_assign() _Node_alloc_traits::_S_propagate_on_move_assign()
|| _Node_alloc_traits::_S_always_equal(); || _Node_alloc_traits::_S_always_equal();
_M_move_assign(std::move(__list), __bool_constant<__move_storage>()); _M_move_assign(std::move(__list), __bool_constant<__move_storage>());
return *this; return *this;
} }
...@@ -615,8 +641,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -615,8 +641,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
forward_list& forward_list&
operator=(std::initializer_list<_Tp> __il) operator=(std::initializer_list<_Tp> __il)
{ {
assign(__il); assign(__il);
return *this; return *this;
} }
/** /**
...@@ -634,8 +660,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -634,8 +660,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _InputIterator, template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>> typename = std::_RequireInputIter<_InputIterator>>
void void
assign(_InputIterator __first, _InputIterator __last) assign(_InputIterator __first, _InputIterator __last)
{ {
typedef is_assignable<_Tp, decltype(*__first)> __assignable; typedef is_assignable<_Tp, decltype(*__first)> __assignable;
_M_assign(__first, __last, __assignable()); _M_assign(__first, __last, __assignable());
} }
...@@ -714,7 +740,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -714,7 +740,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
iterator iterator
end() noexcept end() noexcept
{ return iterator(0); } { return iterator(nullptr); }
/** /**
* Returns a read-only iterator that points one past the last * Returns a read-only iterator that points one past the last
...@@ -723,7 +749,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -723,7 +749,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
const_iterator const_iterator
end() const noexcept end() const noexcept
{ return const_iterator(0); } { return const_iterator(nullptr); }
/** /**
* Returns a read-only (constant) iterator that points to the * Returns a read-only (constant) iterator that points to the
...@@ -750,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -750,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
const_iterator const_iterator
cend() const noexcept cend() const noexcept
{ return const_iterator(0); } { return const_iterator(nullptr); }
/** /**
* Returns true if the %forward_list is empty. (Thus begin() would * Returns true if the %forward_list is empty. (Thus begin() would
...@@ -758,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -758,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
bool bool
empty() const noexcept 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. * Returns the largest possible number of elements of %forward_list.
...@@ -776,8 +802,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -776,8 +802,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
reference reference
front() front()
{ {
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next); _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return *__front->_M_valptr(); return *__front->_M_valptr();
} }
/** /**
...@@ -787,8 +813,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -787,8 +813,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const_reference const_reference
front() const front() const
{ {
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next); _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return *__front->_M_valptr(); return *__front->_M_valptr();
} }
// 23.3.4.5 modifiers: // 23.3.4.5 modifiers:
...@@ -806,14 +832,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -806,14 +832,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
template<typename... _Args> template<typename... _Args>
#if __cplusplus > 201402L #if __cplusplus > 201402L
reference reference
#else #else
void void
#endif #endif
emplace_front(_Args&&... __args) emplace_front(_Args&&... __args)
{ {
this->_M_insert_after(cbefore_begin(), this->_M_insert_after(cbefore_begin(),
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
#if __cplusplus > 201402L #if __cplusplus > 201402L
return front(); return front();
#endif #endif
...@@ -870,10 +896,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -870,10 +896,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* and references. * and references.
*/ */
template<typename... _Args> template<typename... _Args>
iterator iterator
emplace_after(const_iterator __pos, _Args&&... __args) emplace_after(const_iterator __pos, _Args&&... __args)
{ return iterator(this->_M_insert_after(__pos, { return iterator(this->_M_insert_after(__pos,
std::forward<_Args>(__args)...)); } std::forward<_Args>(__args)...)); }
/** /**
* @brief Inserts given value into %forward_list after specified * @brief Inserts given value into %forward_list after specified
...@@ -933,9 +959,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -933,9 +959,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
template<typename _InputIterator, template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>> typename = std::_RequireInputIter<_InputIterator>>
iterator iterator
insert_after(const_iterator __pos, insert_after(const_iterator __pos,
_InputIterator __first, _InputIterator __last); _InputIterator __first, _InputIterator __last);
/** /**
* @brief Inserts the contents of an initializer_list into * @brief Inserts the contents of an initializer_list into
...@@ -1018,10 +1044,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1018,10 +1044,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void void
swap(forward_list& __list) noexcept 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); __list._M_impl._M_head._M_next);
_Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(), _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
__list._M_get_Node_allocator()); __list._M_get_Node_allocator());
} }
/** /**
...@@ -1063,7 +1089,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1063,7 +1089,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
clear() noexcept 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: // 23.3.4.6 forward_list operations:
...@@ -1101,11 +1127,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1101,11 +1127,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
splice_after(const_iterator __pos, forward_list&& __list, splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __i) noexcept; const_iterator __i) noexcept;
void void
splice_after(const_iterator __pos, forward_list& __list, splice_after(const_iterator __pos, forward_list& __list,
const_iterator __i) noexcept const_iterator __i) noexcept
{ splice_after(__pos, std::move(__list), __i); } { splice_after(__pos, std::move(__list), __i); }
/** /**
...@@ -1124,12 +1150,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1124,12 +1150,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
splice_after(const_iterator __pos, forward_list&&, 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); } { _M_splice_after(__pos, __before, __last); }
void void
splice_after(const_iterator __pos, forward_list&, 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); } { _M_splice_after(__pos, __before, __last); }
// @} // @}
...@@ -1159,8 +1185,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1159,8 +1185,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* responsibility. * responsibility.
*/ */
template<typename _Pred> template<typename _Pred>
void void
remove_if(_Pred __pred); remove_if(_Pred __pred);
/** /**
* @brief Remove consecutive duplicate elements. * @brief Remove consecutive duplicate elements.
...@@ -1189,8 +1215,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1189,8 +1215,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* Managing the pointer is the user's responsibility. * Managing the pointer is the user's responsibility.
*/ */
template<typename _BinPred> template<typename _BinPred>
void void
unique(_BinPred __binary_pred); unique(_BinPred __binary_pred);
/** /**
* @brief Merge sorted lists. * @brief Merge sorted lists.
...@@ -1221,13 +1247,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1221,13 +1247,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* according to comp(). * according to comp().
*/ */
template<typename _Comp> template<typename _Comp>
void void
merge(forward_list&& __list, _Comp __comp); merge(forward_list&& __list, _Comp __comp);
template<typename _Comp> template<typename _Comp>
void void
merge(forward_list& __list, _Comp __comp) merge(forward_list& __list, _Comp __comp)
{ merge(std::move(__list), __comp); } { merge(std::move(__list), __comp); }
/** /**
* @brief Sort the elements of the list. * @brief Sort the elements of the list.
...@@ -1246,8 +1272,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1246,8 +1272,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* elements remain in list order. * elements remain in list order.
*/ */
template<typename _Comp> template<typename _Comp>
void void
sort(_Comp __comp); sort(_Comp __comp);
/** /**
* @brief Reverse the elements in list. * @brief Reverse the elements in list.
...@@ -1261,8 +1287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1261,8 +1287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
private: private:
// Called by the range constructor to implement [23.3.4.2]/9 // Called by the range constructor to implement [23.3.4.2]/9
template<typename _InputIterator> template<typename _InputIterator>
void void
_M_range_initialize(_InputIterator __first, _InputIterator __last); _M_range_initialize(_InputIterator __first, _InputIterator __last);
// Called by forward_list(n,v,a), and the range constructor when it // Called by forward_list(n,v,a), and the range constructor when it
// turns out to be the same thing. // turns out to be the same thing.
...@@ -1284,22 +1310,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1284,22 +1310,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// Called by operator=(forward_list&&) // Called by operator=(forward_list&&)
void void
_M_move_assign(forward_list&& __list, std::true_type) noexcept _M_move_assign(forward_list&& __list, true_type) noexcept
{ {
clear(); clear();
this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next; this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
__list._M_impl._M_head._M_next = nullptr; __list._M_impl._M_head._M_next = nullptr;
std::__alloc_on_move(this->_M_get_Node_allocator(), std::__alloc_on_move(this->_M_get_Node_allocator(),
__list._M_get_Node_allocator()); __list._M_get_Node_allocator());
} }
// Called by operator=(forward_list&&) // Called by operator=(forward_list&&)
void 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()) if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
_M_move_assign(std::move(__list), std::true_type()); _M_move_assign(std::move(__list), true_type());
else else
// The rvalue's allocator cannot be moved, or is not equal, // The rvalue's allocator cannot be moved, or is not equal,
// so we need to individually move each element. // so we need to individually move each element.
this->assign(std::__make_move_if_noexcept_iterator(__list.begin()), this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
...@@ -1310,7 +1336,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1310,7 +1336,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// CopyAssignable. // CopyAssignable.
template<typename _InputIterator> template<typename _InputIterator>
void void
_M_assign(_InputIterator __first, _InputIterator __last, true_type) _M_assign(_InputIterator __first, _InputIterator __last, true_type)
{ {
auto __prev = before_begin(); auto __prev = before_begin();
auto __curr = begin(); auto __curr = begin();
...@@ -1326,13 +1352,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1326,13 +1352,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
insert_after(__prev, __first, __last); insert_after(__prev, __first, __last);
else if (__curr != __end) else if (__curr != __end)
erase_after(__prev, __end); erase_after(__prev, __end);
} }
// Called by assign(_InputIterator, _InputIterator) if _Tp is not // Called by assign(_InputIterator, _InputIterator) if _Tp is not
// CopyAssignable. // CopyAssignable.
template<typename _InputIterator> template<typename _InputIterator>
void void
_M_assign(_InputIterator __first, _InputIterator __last, false_type) _M_assign(_InputIterator __first, _InputIterator __last, false_type)
{ {
clear(); clear();
insert_after(cbefore_begin(), __first, __last); insert_after(cbefore_begin(), __first, __last);
...@@ -1383,14 +1409,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1383,14 +1409,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @param __ly A %forward_list of the same type as @a __lx. * @param __ly A %forward_list of the same type as @a __lx.
* @return True iff the elements of the forward lists are equal. * @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 * elements of the forward lists. Deques are considered equivalent
* if corresponding elements compare equal. * if corresponding elements compare equal.
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
bool bool
operator==(const forward_list<_Tp, _Alloc>& __lx, operator==(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly); const forward_list<_Tp, _Alloc>& __ly);
/** /**
* @brief Forward list ordering relation. * @brief Forward list ordering relation.
...@@ -1398,7 +1424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1398,7 +1424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @param __ly A %forward_list of the same type as @a __lx. * @param __ly A %forward_list of the same type as @a __lx.
* @return True iff @a __lx is lexicographically less than @a __ly. * @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 * elements of the forward lists. The elements must be comparable
* with @c <. * with @c <.
* *
...@@ -1407,7 +1433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1407,7 +1433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator<(const forward_list<_Tp, _Alloc>& __lx, 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(), { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
__ly.cbegin(), __ly.cend()); } __ly.cbegin(), __ly.cend()); }
...@@ -1415,28 +1441,28 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1415,28 +1441,28 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator!=(const forward_list<_Tp, _Alloc>& __lx, operator!=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return !(__lx == __ly); } { return !(__lx == __ly); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator>(const forward_list<_Tp, _Alloc>& __lx, operator>(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return (__ly < __lx); } { return (__ly < __lx); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator>=(const forward_list<_Tp, _Alloc>& __lx, operator>=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return !(__lx < __ly); } { return !(__lx < __ly); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator<=(const forward_list<_Tp, _Alloc>& __lx, operator<=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return !(__ly < __lx); } { return !(__ly < __lx); }
/// See std::forward_list::swap(). /// See std::forward_list::swap().
......
...@@ -41,12 +41,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -41,12 +41,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _M_impl(std::move(__a)) : _M_impl(std::move(__a))
{ {
if (__lst._M_get_Node_allocator() == _M_get_Node_allocator()) if (__lst._M_get_Node_allocator() == _M_get_Node_allocator())
{ this->_M_impl._M_head = std::move(__lst._M_impl._M_head);
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;
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -55,12 +50,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -55,12 +50,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_M_insert_after(const_iterator __pos, _Args&&... __args) _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); = const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(std::forward<_Args>(__args)...); _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
__thing->_M_next = __to->_M_next; __thing->_M_next = __to->_M_next;
__to->_M_next = __thing; __to->_M_next = __thing;
return __to->_M_next; return __to->_M_next;
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -80,19 +75,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -80,19 +75,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
_Fwd_list_node_base* _Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(_Fwd_list_node_base* __pos, _M_erase_after(_Fwd_list_node_base* __pos,
_Fwd_list_node_base* __last) _Fwd_list_node_base* __last)
{ {
_Node* __curr = static_cast<_Node*>(__pos->_M_next); _Node* __curr = static_cast<_Node*>(__pos->_M_next);
while (__curr != __last) while (__curr != __last)
{ {
_Node* __temp = __curr; _Node* __temp = __curr;
__curr = static_cast<_Node*>(__curr->_M_next); __curr = static_cast<_Node*>(__curr->_M_next);
_Tp_alloc_type __a(_M_get_Node_allocator()); _Tp_alloc_type __a(_M_get_Node_allocator());
allocator_traits<_Tp_alloc_type>::destroy(__a, __temp->_M_valptr()); allocator_traits<_Tp_alloc_type>::destroy(__a, __temp->_M_valptr());
__temp->~_Node(); __temp->~_Node();
_M_put_node(__temp); _M_put_node(__temp);
} }
__pos->_M_next = __last; __pos->_M_next = __last;
return __last; return __last;
} }
...@@ -104,12 +99,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -104,12 +99,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
forward_list<_Tp, _Alloc>:: forward_list<_Tp, _Alloc>::
_M_range_initialize(_InputIterator __first, _InputIterator __last) _M_range_initialize(_InputIterator __first, _InputIterator __last)
{ {
_Node_base* __to = &this->_M_impl._M_head; _Node_base* __to = &this->_M_impl._M_head;
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
{ {
__to->_M_next = this->_M_create_node(*__first); __to->_M_next = this->_M_create_node(*__first);
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
// Called by forward_list(n,v,a). // Called by forward_list(n,v,a).
...@@ -120,10 +115,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -120,10 +115,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ {
_Node_base* __to = &this->_M_impl._M_head; _Node_base* __to = &this->_M_impl._M_head;
for (; __n; --__n) for (; __n; --__n)
{ {
__to->_M_next = this->_M_create_node(__value); __to->_M_next = this->_M_create_node(__value);
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -133,10 +128,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -133,10 +128,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ {
_Node_base* __to = &this->_M_impl._M_head; _Node_base* __to = &this->_M_impl._M_head;
for (; __n; --__n) for (; __n; --__n)
{ {
__to->_M_next = this->_M_create_node(); __to->_M_next = this->_M_create_node();
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -145,21 +140,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -145,21 +140,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
operator=(const forward_list& __list) operator=(const forward_list& __list)
{ {
if (std::__addressof(__list) != this) if (std::__addressof(__list) != this)
{ {
if (_Node_alloc_traits::_S_propagate_on_copy_assign()) if (_Node_alloc_traits::_S_propagate_on_copy_assign())
{ {
auto& __this_alloc = this->_M_get_Node_allocator(); auto& __this_alloc = this->_M_get_Node_allocator();
auto& __that_alloc = __list._M_get_Node_allocator(); auto& __that_alloc = __list._M_get_Node_allocator();
if (!_Node_alloc_traits::_S_always_equal() if (!_Node_alloc_traits::_S_always_equal()
&& __this_alloc != __that_alloc) && __this_alloc != __that_alloc)
{ {
// replacement allocator cannot free existing storage // replacement allocator cannot free existing storage
clear(); clear();
} }
std::__alloc_on_copy(__this_alloc, __that_alloc); std::__alloc_on_copy(__this_alloc, __that_alloc);
} }
assign(__list.cbegin(), __list.cend()); assign(__list.cbegin(), __list.cend());
} }
return *this; return *this;
} }
...@@ -190,12 +185,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -190,12 +185,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
size_type __len = 0; size_type __len = 0;
while (__k._M_next() != end() && __len < __sz) while (__k._M_next() != end() && __len < __sz)
{ {
++__k; ++__k;
++__len; ++__len;
} }
if (__len == __sz) if (__len == __sz)
erase_after(__k, end()); erase_after(__k, end());
else else
_M_default_insert_after(__k, __sz - __len); _M_default_insert_after(__k, __sz - __len);
} }
...@@ -209,14 +204,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -209,14 +204,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
size_type __len = 0; size_type __len = 0;
while (__k._M_next() != end() && __len < __sz) while (__k._M_next() != end() && __len < __sz)
{ {
++__k; ++__k;
++__len; ++__len;
} }
if (__len == __sz) if (__len == __sz)
erase_after(__k, end()); erase_after(__k, end());
else else
insert_after(__k, __sz - __len, __val); insert_after(__k, __sz - __len, __val);
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -233,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -233,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
__end = __end->_M_next; __end = __end->_M_next;
if (__b != __end) if (__b != __end)
return iterator(__tmp->_M_transfer_after(__b, __end)); return iterator(__tmp->_M_transfer_after(__b, __end));
else else
return iterator(__tmp); return iterator(__tmp);
} }
...@@ -292,8 +287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -292,8 +287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Node_base* __extra = nullptr; _Node_base* __extra = nullptr;
while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next)) 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)) if (__tmp->_M_valptr() != std::__addressof(__val))
{ {
...@@ -304,7 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -304,7 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
__extra = __curr; __extra = __curr;
} }
__curr = __curr->_M_next; __curr = __curr->_M_next;
} }
if (__extra) if (__extra)
this->_M_erase_after(__extra); this->_M_erase_after(__extra);
...@@ -317,13 +312,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -317,13 +312,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
remove_if(_Pred __pred) remove_if(_Pred __pred)
{ {
_Node_base* __curr = &this->_M_impl._M_head; _Node_base* __curr = &this->_M_impl._M_head;
while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next)) while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
{ {
if (__pred(*__tmp->_M_valptr())) if (__pred(*__tmp->_M_valptr()))
this->_M_erase_after(__curr); this->_M_erase_after(__curr);
else else
__curr = __curr->_M_next; __curr = __curr->_M_next;
} }
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -332,19 +327,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -332,19 +327,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
forward_list<_Tp, _Alloc>:: forward_list<_Tp, _Alloc>::
unique(_BinPred __binary_pred) unique(_BinPred __binary_pred)
{ {
iterator __first = begin(); iterator __first = begin();
iterator __last = end(); iterator __last = end();
if (__first == __last) if (__first == __last)
return; return;
iterator __next = __first; iterator __next = __first;
while (++__next != __last) while (++__next != __last)
{ {
if (__binary_pred(*__first, *__next)) if (__binary_pred(*__first, *__next))
erase_after(__first); erase_after(__first);
else else
__first = __next; __first = __next;
__next = __first; __next = __first;
} }
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -353,44 +348,42 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -353,44 +348,42 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
forward_list<_Tp, _Alloc>:: forward_list<_Tp, _Alloc>::
merge(forward_list&& __list, _Comp __comp) merge(forward_list&& __list, _Comp __comp)
{ {
_Node_base* __node = &this->_M_impl._M_head; _Node_base* __node = &this->_M_impl._M_head;
while (__node->_M_next && __list._M_impl._M_head._M_next) while (__node->_M_next && __list._M_impl._M_head._M_next)
{ {
if (__comp(*static_cast<_Node*> if (__comp(*static_cast<_Node*>
(__list._M_impl._M_head._M_next)->_M_valptr(), (__list._M_impl._M_head._M_next)->_M_valptr(),
*static_cast<_Node*> *static_cast<_Node*>
(__node->_M_next)->_M_valptr())) (__node->_M_next)->_M_valptr()))
__node->_M_transfer_after(&__list._M_impl._M_head, __node->_M_transfer_after(&__list._M_impl._M_head,
__list._M_impl._M_head._M_next); __list._M_impl._M_head._M_next);
__node = __node->_M_next; __node = __node->_M_next;
} }
if (__list._M_impl._M_head._M_next)
{ if (__list._M_impl._M_head._M_next)
__node->_M_next = __list._M_impl._M_head._M_next; *__node = std::move(__list._M_impl._M_head);
__list._M_impl._M_head._M_next = 0;
}
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
bool bool
operator==(const forward_list<_Tp, _Alloc>& __lx, 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 // We don't have size() so we need to walk through both lists
// making sure both iterators are valid. // making sure both iterators are valid.
auto __ix = __lx.cbegin(); auto __ix = __lx.cbegin();
auto __iy = __ly.cbegin(); auto __iy = __ly.cbegin();
while (__ix != __lx.cend() && __iy != __ly.cend()) while (__ix != __lx.cend() && __iy != __ly.cend())
{ {
if (*__ix != *__iy) if (*__ix != *__iy)
return false; return false;
++__ix; ++__ix;
++__iy; ++__iy;
} }
if (__ix == __lx.cend() && __iy == __ly.cend()) if (__ix == __lx.cend() && __iy == __ly.cend())
return true; return true;
else else
return false; return false;
} }
template<typename _Tp, class _Alloc> template<typename _Tp, class _Alloc>
...@@ -399,103 +392,102 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -399,103 +392,102 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
forward_list<_Tp, _Alloc>:: forward_list<_Tp, _Alloc>::
sort(_Comp __comp) sort(_Comp __comp)
{ {
// If `next' is 0, return immediately. // If `next' is nullptr, return immediately.
_Node* __list = static_cast<_Node*>(this->_M_impl._M_head._M_next); _Node* __list = static_cast<_Node*>(this->_M_impl._M_head._M_next);
if (!__list) if (!__list)
return; return;
unsigned long __insize = 1; unsigned long __insize = 1;
while (1) while (1)
{ {
_Node* __p = __list; _Node* __p = __list;
__list = 0; __list = nullptr;
_Node* __tail = 0; _Node* __tail = nullptr;
// Count number of merges we do in this pass. // Count number of merges we do in this pass.
unsigned long __nmerges = 0; unsigned long __nmerges = 0;
while (__p) while (__p)
{ {
++__nmerges; ++__nmerges;
// There exists a merge to be done. // There exists a merge to be done.
// Step `insize' places along from p. // Step `insize' places along from p.
_Node* __q = __p; _Node* __q = __p;
unsigned long __psize = 0; unsigned long __psize = 0;
for (unsigned long __i = 0; __i < __insize; ++__i) for (unsigned long __i = 0; __i < __insize; ++__i)
{ {
++__psize; ++__psize;
__q = static_cast<_Node*>(__q->_M_next); __q = static_cast<_Node*>(__q->_M_next);
if (!__q) if (!__q)
break; break;
} }
// If q hasn't fallen off end, we have two lists to merge. // If q hasn't fallen off end, we have two lists to merge.
unsigned long __qsize = __insize; unsigned long __qsize = __insize;
// Now we have two lists; merge them. // Now we have two lists; merge them.
while (__psize > 0 || (__qsize > 0 && __q)) while (__psize > 0 || (__qsize > 0 && __q))
{ {
// Decide whether next node of merge comes from p or q. // Decide whether next node of merge comes from p or q.
_Node* __e; _Node* __e;
if (__psize == 0) if (__psize == 0)
{ {
// p is empty; e must come from q. // p is empty; e must come from q.
__e = __q; __e = __q;
__q = static_cast<_Node*>(__q->_M_next); __q = static_cast<_Node*>(__q->_M_next);
--__qsize; --__qsize;
} }
else if (__qsize == 0 || !__q) else if (__qsize == 0 || !__q)
{ {
// q is empty; e must come from p. // q is empty; e must come from p.
__e = __p; __e = __p;
__p = static_cast<_Node*>(__p->_M_next); __p = static_cast<_Node*>(__p->_M_next);
--__psize; --__psize;
} }
else if (__comp(*__p->_M_valptr(), *__q->_M_valptr())) else if (__comp(*__p->_M_valptr(), *__q->_M_valptr()))
{ {
// First node of p is lower; e must come from p. // First node of p is lower; e must come from p.
__e = __p; __e = __p;
__p = static_cast<_Node*>(__p->_M_next); __p = static_cast<_Node*>(__p->_M_next);
--__psize; --__psize;
} }
else else
{ {
// First node of q is lower; e must come from q. // First node of q is lower; e must come from q.
__e = __q; __e = __q;
__q = static_cast<_Node*>(__q->_M_next); __q = static_cast<_Node*>(__q->_M_next);
--__qsize; --__qsize;
} }
// Add the next node to the merged list. // Add the next node to the merged list.
if (__tail) if (__tail)
__tail->_M_next = __e; __tail->_M_next = __e;
else else
__list = __e; __list = __e;
__tail = __e; __tail = __e;
} }
// Now p has stepped `insize' places along, and q has too. // Now p has stepped `insize' places along, and q has too.
__p = __q; __p = __q;
} }
__tail->_M_next = 0; __tail->_M_next = nullptr;
// If we have done only one merge, we're finished. // If we have done only one merge, we're finished.
// Allow for nmerges == 0, the empty list case. // Allow for nmerges == 0, the empty list case.
if (__nmerges <= 1) if (__nmerges <= 1)
{ {
this->_M_impl._M_head._M_next = __list; this->_M_impl._M_head._M_next = __list;
return; return;
} }
// Otherwise repeat, merging lists twice the size. // Otherwise repeat, merging lists twice the size.
__insize *= 2; __insize *= 2;
} }
} }
_GLIBCXX_END_NAMESPACE_CONTAINER _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace std } // namespace std
#endif /* _FORWARD_LIST_TCC */ #endif /* _FORWARD_LIST_TCC */
// Copyright (C) 2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <forward_list>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
#include <ext/aligned_buffer.h>
using T = int;
using __gnu_test::default_init_allocator;
void test01()
{
typedef default_init_allocator<T> alloc_type;
typedef std::forward_list<T, alloc_type> test_type;
__gnu_cxx::__aligned_buffer<test_type> buf;
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
test_type *tmp = ::new(buf._M_addr()) test_type;
VERIFY( tmp->get_allocator().state == 0 );
tmp->~test_type();
}
void test02()
{
typedef default_init_allocator<T> alloc_type;
typedef std::forward_list<T, alloc_type> test_type;
__gnu_cxx::__aligned_buffer<test_type> buf;
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
test_type *tmp = ::new(buf._M_addr()) test_type();
VERIFY( tmp->get_allocator().state == 0 );
tmp->~test_type();
}
int main()
{
test01();
test02();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment