Commit b0b4a253 by Jonathan Wakely

forward_list.h (forward_list): Adjust comments.

	* include/bits/forward_list.h (forward_list): Adjust comments.
	(forward_list(const forward_list&, const _Alloc&)): Use
	_M_range_initialize to copy elements.
	(forward_list(forward_list&&, const _Alloc&)): Add exception
	specification.
	(_Fwd_list_base(const _Fwd_list_base&, const _Node_alloc_type&)):
	Remove.
	* include/bits/forward_list.tcc (_Fwd_list_base(const _Fwd_list_base&,
	const _Node_alloc_type&)): Remove.
	(_Fwd_list_base(_Fwd_list_base&&, const _Node_alloc_type&)): Fix
	memory leak when allocators are not equal.

From-SVN: r193009
parent 4e1866fe
2012-10-31 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/forward_list.h (forward_list): Adjust comments.
(forward_list(const forward_list&, const _Alloc&)): Use
_M_range_initialize to copy elements.
(forward_list(forward_list&&, const _Alloc&)): Add exception
specification.
(_Fwd_list_base(const _Fwd_list_base&, const _Node_alloc_type&)):
Remove.
* include/bits/forward_list.tcc (_Fwd_list_base(const _Fwd_list_base&,
const _Node_alloc_type&)): Remove.
(_Fwd_list_base(_Fwd_list_base&&, const _Node_alloc_type&)): Fix
memory leak when allocators are not equal.
2012-10-29 Jonathan Wakely <jwakely.gcc@gmail.com> 2012-10-29 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/55123 PR libstdc++/55123
...@@ -336,7 +350,7 @@ ...@@ -336,7 +350,7 @@
2012-10-09 Daniel Krugler <daniel.kruegler@gmail.com> 2012-10-09 Daniel Krugler <daniel.kruegler@gmail.com>
* include/std/type_traits (common_time): Provide "SFINAE-friendly" * include/std/type_traits (common_type): Provide "SFINAE-friendly"
implementation. implementation.
(__success_type, __failure_type): Fix. (__success_type, __failure_type): Fix.
* include/std/chrono (common_type): Likewise for the chrono::time_point * include/std/chrono (common_type): Likewise for the chrono::time_point
......
...@@ -314,8 +314,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -314,8 +314,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Fwd_list_base(const _Node_alloc_type& __a) _Fwd_list_base(const _Node_alloc_type& __a)
: _M_impl(__a) { } : _M_impl(__a) { }
_Fwd_list_base(const _Fwd_list_base& __lst, const _Node_alloc_type& __a);
_Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a); _Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a);
_Fwd_list_base(_Fwd_list_base&& __lst) _Fwd_list_base(_Fwd_list_base&& __lst)
...@@ -394,14 +392,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -394,14 +392,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* Also unlike the other standard containers, std::forward_list provides * Also unlike the other standard containers, std::forward_list provides
* specialized algorithms %unique to linked lists, such as * specialized algorithms %unique to linked lists, such as
* splicing, sorting, and in-place reversal. * splicing, sorting, and in-place reversal.
*
* A couple points on memory allocation for forward_list<Tp>:
*
* First, we never actually allocate a Tp, we allocate
* Fwd_list_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure
* that after elements from %forward_list<X,Alloc1> are spliced into
* %forward_list<X,Alloc2>, destroying the memory of the second %list is a
* valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
*/ */
template<typename _Tp, typename _Alloc = allocator<_Tp> > template<typename _Tp, typename _Alloc = allocator<_Tp> >
class forward_list : private _Fwd_list_base<_Tp, _Alloc> class forward_list : private _Fwd_list_base<_Tp, _Alloc>
...@@ -429,7 +419,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -429,7 +419,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
// 23.2.3.1 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.
...@@ -446,8 +436,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -446,8 +436,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @param __al An allocator object. * @param __al An allocator object.
*/ */
forward_list(const forward_list& __list, const _Alloc& __al) forward_list(const forward_list& __list, const _Alloc& __al)
: _Base(__list, _Node_alloc_type(__al)) : _Base(_Node_alloc_type(__al))
{ } { _M_range_initialize(__list.begin(), __list.end()); }
/** /**
* @brief Move constructor with allocator argument. * @brief Move constructor with allocator argument.
...@@ -455,6 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -455,6 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @param __al An allocator object. * @param __al An allocator object.
*/ */
forward_list(forward_list&& __list, const _Alloc& __al) forward_list(forward_list&& __list, const _Alloc& __al)
noexcept(_Node_alloc_traits::_S_always_equal())
: _Base(std::move(__list), _Node_alloc_type(__al)) : _Base(std::move(__list), _Node_alloc_type(__al))
{ } { }
...@@ -517,7 +508,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -517,7 +508,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* types. * types.
* *
* The newly-created %forward_list contains the exact contents of @a * The newly-created %forward_list contains the exact contents of @a
* forward_list. The contents of @a __list are a valid, but unspecified * __list. The contents of @a __list are a valid, but unspecified
* %forward_list. * %forward_list.
*/ */
forward_list(forward_list&& __list) noexcept forward_list(forward_list&& __list) noexcept
...@@ -647,7 +638,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -647,7 +638,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
get_allocator() const noexcept get_allocator() const noexcept
{ return allocator_type(this->_M_get_Node_allocator()); } { return allocator_type(this->_M_get_Node_allocator()); }
// 23.2.3.2 iterators: // 23.3.4.3 iterators:
/** /**
* Returns a read/write iterator that points before the first element * Returns a read/write iterator that points before the first element
...@@ -743,7 +734,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -743,7 +734,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
max_size() const noexcept max_size() const noexcept
{ return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); } { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
// 23.2.3.3 element access: // 23.3.4.4 element access:
/** /**
* Returns a read/write reference to the data at the first * Returns a read/write reference to the data at the first
...@@ -767,7 +758,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -767,7 +758,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return __front->_M_value; return __front->_M_value;
} }
// 23.2.3.4 modifiers: // 23.3.4.5 modifiers:
/** /**
* @brief Constructs object in %forward_list at the front of the * @brief Constructs object in %forward_list at the front of the
...@@ -1031,7 +1022,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1031,7 +1022,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
clear() noexcept clear() noexcept
{ this->_M_erase_after(&this->_M_impl._M_head, 0); } { this->_M_erase_after(&this->_M_impl._M_head, 0); }
// 23.2.3.5 forward_list operations: // 23.3.4.6 forward_list operations:
/** /**
* @brief Insert contents of another %forward_list. * @brief Insert contents of another %forward_list.
...@@ -1223,7 +1214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1223,7 +1214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ this->_M_impl._M_head._M_reverse_after(); } { this->_M_impl._M_head._M_reverse_after(); }
private: private:
// Called by the range constructor to implement [23.1.1]/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);
......
...@@ -36,28 +36,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -36,28 +36,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_Fwd_list_base(const _Fwd_list_base& __lst, const _Node_alloc_type& __a)
: _M_impl(__a)
{
this->_M_impl._M_head._M_next = 0;
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
_Node* __curr = static_cast<_Node*>(__lst._M_impl._M_head._M_next);
while (__curr)
{
__to->_M_next = _M_create_node(__curr->_M_value);
__to = __to->_M_next;
__curr = static_cast<_Node*>(__curr->_M_next);
}
}
template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>::
_Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a) _Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a)
: _M_impl(__a) : _M_impl(__a)
{ {
if (__lst._M_get_Node_allocator() == __a) if (__lst._M_get_Node_allocator() == __a)
{
this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next; this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
__lst._M_impl._M_head._M_next = 0;
}
else else
{ {
this->_M_impl._M_head._M_next = 0; this->_M_impl._M_head._M_next = 0;
...@@ -72,7 +58,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -72,7 +58,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
__curr = static_cast<_Node*>(__curr->_M_next); __curr = static_cast<_Node*>(__curr->_M_next);
} }
} }
__lst._M_impl._M_head._M_next = 0;
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -119,7 +104,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -119,7 +104,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return __last; return __last;
} }
// Called by the range constructor to implement [23.1.1]/9 // Called by the range constructor to implement [23.3.4.2]/9
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
template<typename _InputIterator> template<typename _InputIterator>
void void
......
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