forward_list.h (splice_after(const_iterator, forward_list&), [...]): Add per C++11 as published (and LWG 1310).

2012-04-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/forward_list.h (splice_after(const_iterator,
	forward_list&), splice_after(const_iterator, forward_list&,
	consst_iterator), splice_after(const_iterator, forward_list&,
	const_iterator, const_iterator), merge(forward_list&),
	merge(forward_list&, _Comp)): Add per C++11 as published (and
	LWG 1310).
	* include/debug/forward_list: Adjust.

	* include/bits/forward_list.h (splice_after(const_iterator,
	forward_list&&, const_iterator)): Only declare.
	(_M_transfer_after): Remove.
	(_M_splice_after(const_iterator, forward_list&&)): Change signature.
	(splice_after(const_iterator, forward_list&&, const_iterator,
	const_iterator)): Use the latter.
	* include/bits/forward_list.tcc (splice_after(const_iterator,
	forward_list&&, const_iterator)): Define here.
	(_M_splice_after): Define, use throughout.

	* include/bits/forward_list.h (insert_after(const_iterator,
	std::initializer_list<_Tp>)): Forward to insert_after(const_iterator,
	_InputIterator, _InputIterator).
	* include/bits/forward_list.tcc: Remove definition.

	* testsuite/23_containers/forward_list/modifiers/6.cc: New.
	* testsuite/23_containers/forward_list/operations/1.cc: Adjust.

From-SVN: r186338
This commit is contained in:
Paolo Carlini 2012-04-11 17:31:57 +00:00 committed by Paolo Carlini
parent 3dee490545
commit 7826329699
6 changed files with 204 additions and 49 deletions

View File

@ -1,3 +1,31 @@
2012-04-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h (splice_after(const_iterator,
forward_list&), splice_after(const_iterator, forward_list&,
consst_iterator), splice_after(const_iterator, forward_list&,
const_iterator, const_iterator), merge(forward_list&),
merge(forward_list&, _Comp)): Add per C++11 as published (and
LWG 1310).
* include/debug/forward_list: Adjust.
* include/bits/forward_list.h (splice_after(const_iterator,
forward_list&&, const_iterator)): Only declare.
(_M_transfer_after): Remove.
(_M_splice_after(const_iterator, forward_list&&)): Change signature.
(splice_after(const_iterator, forward_list&&, const_iterator,
const_iterator)): Use the latter.
* include/bits/forward_list.tcc (splice_after(const_iterator,
forward_list&&, const_iterator)): Define here.
(_M_splice_after): Define, use throughout.
* include/bits/forward_list.h (insert_after(const_iterator,
std::initializer_list<_Tp>)): Forward to insert_after(const_iterator,
_InputIterator, _InputIterator).
* include/bits/forward_list.tcc: Remove definition.
* testsuite/23_containers/forward_list/modifiers/6.cc: New.
* testsuite/23_containers/forward_list/operations/1.cc: Adjust.
2012-04-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/52931

View File

@ -52,15 +52,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Fwd_list_node_base* _M_next;
_Fwd_list_node_base*
_M_transfer_after(_Fwd_list_node_base* __begin)
{
_Fwd_list_node_base* __end = __begin;
while (__end && __end->_M_next)
__end = __end->_M_next;
return _M_transfer_after(__begin, __end);
}
_Fwd_list_node_base*
_M_transfer_after(_Fwd_list_node_base* __begin,
_Fwd_list_node_base* __end)
@ -925,7 +916,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* does not invalidate iterators and references.
*/
iterator
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il);
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{ return insert_after(__pos, __il.begin(), __il.end()); }
/**
* @brief Removes the element pointed to by the iterator following
@ -1047,9 +1039,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
splice_after(const_iterator __pos, forward_list&& __list)
{
if (!__list.empty())
_M_splice_after(__pos, std::move(__list));
_M_splice_after(__pos, __list.before_begin(), __list.end());
}
void
splice_after(const_iterator __pos, forward_list& __list)
{ splice_after(__pos, std::move(__list)); }
/**
* @brief Insert element from another %forward_list.
* @param __pos Iterator referencing the element to insert after.
@ -1062,15 +1058,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/
void
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __i)
{
const_iterator __j = __i;
++__j;
if (__pos == __i || __pos == __j)
return;
const_iterator __i);
splice_after(__pos, std::move(__list), __i, __j);
}
void
splice_after(const_iterator __pos, forward_list& __list,
const_iterator __i)
{ splice_after(__pos, std::move(__list), __i); }
/**
* @brief Insert range from another %forward_list.
@ -1086,8 +1079,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* Undefined if @a __pos is in (__before,__last).
*/
void
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __before, const_iterator __last);
splice_after(const_iterator __pos, forward_list&&,
const_iterator __before, const_iterator __last)
{ _M_splice_after(__pos, __before, __last); }
void
splice_after(const_iterator __pos, forward_list&,
const_iterator __before, const_iterator __last)
{ _M_splice_after(__pos, __before, __last); }
/**
* @brief Remove all elements equal to value.
@ -1130,7 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/
void
unique()
{ this->unique(std::equal_to<_Tp>()); }
{ unique(std::equal_to<_Tp>()); }
/**
* @brief Remove consecutive elements satisfying a predicate.
@ -1159,7 +1158,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/
void
merge(forward_list&& __list)
{ this->merge(std::move(__list), std::less<_Tp>()); }
{ merge(std::move(__list), std::less<_Tp>()); }
void
merge(forward_list& __list)
{ merge(std::move(__list)); }
/**
* @brief Merge sorted lists according to comparison function.
@ -1176,6 +1179,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void
merge(forward_list&& __list, _Comp __comp);
template<typename _Comp>
void
merge(forward_list& __list, _Comp __comp)
{ merge(std::move(__list), __comp); }
/**
* @brief Sort the elements of the list.
*
@ -1184,7 +1192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/
void
sort()
{ this->sort(std::less<_Tp>()); }
{ sort(std::less<_Tp>()); }
/**
* @brief Sort the forward_list using a comparison function.
@ -1218,7 +1226,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// Called by splice_after and insert_after.
iterator
_M_splice_after(const_iterator __pos, forward_list&& __list);
_M_splice_after(const_iterator __pos, const_iterator __before,
const_iterator __last);
// Called by forward_list(n).
void

View File

@ -223,22 +223,37 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, typename _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::
_M_splice_after(const_iterator __pos, forward_list&& __list)
_M_splice_after(const_iterator __pos,
const_iterator __before, const_iterator __last)
{
_Node_base* __tmp = const_cast<_Node_base*>(__pos._M_node);
iterator __before = __list.before_begin();
return iterator(__tmp->_M_transfer_after(__before._M_node));
_Node_base* __b = const_cast<_Node_base*>(__before._M_node);
_Node_base* __end = __b;
while (__end && __end->_M_next != __last._M_node)
__end = __end->_M_next;
if (__b != __end)
return iterator(__tmp->_M_transfer_after(__b, __end));
else
return iterator(__tmp);
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
splice_after(const_iterator __pos, forward_list&&,
const_iterator __before, const_iterator __last)
const_iterator __i)
{
const_iterator __j = __i;
++__j;
if (__pos == __i || __pos == __j)
return;
_Node_base* __tmp = const_cast<_Node_base*>(__pos._M_node);
__tmp->_M_transfer_after(const_cast<_Node_base*>(__before._M_node),
const_cast<_Node_base*>(__last._M_node));
__tmp->_M_transfer_after(const_cast<_Node_base*>(__i._M_node),
const_cast<_Node_base*>(__j._M_node));
}
template<typename _Tp, typename _Alloc>
@ -249,7 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
if (__n)
{
forward_list __tmp(__n, __val, get_allocator());
return _M_splice_after(__pos, std::move(__tmp));
return _M_splice_after(__pos, __tmp.before_begin(), __tmp.end());
}
else
return iterator(const_cast<_Node_base*>(__pos._M_node));
@ -264,25 +279,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
forward_list __tmp(__first, __last, get_allocator());
if (!__tmp.empty())
return _M_splice_after(__pos, std::move(__tmp));
return _M_splice_after(__pos, __tmp.before_begin(), __tmp.end());
else
return iterator(const_cast<_Node_base*>(__pos._M_node));
}
template<typename _Tp, typename _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{
if (__il.size())
{
forward_list __tmp(__il, get_allocator());
return _M_splice_after(__pos, std::move(__tmp));
}
else
return iterator(const_cast<_Node_base*>(__pos._M_node));
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::

View File

@ -417,6 +417,10 @@ namespace __debug
_Base::splice_after(__pos.base(), std::move(__list._M_base()));
}
void
splice_after(const_iterator __pos, forward_list& __list)
{ splice_after(__pos, std::move(__list)); }
void
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __i)
@ -439,6 +443,11 @@ namespace __debug
__i.base());
}
void
splice_after(const_iterator __pos, forward_list& __list,
const_iterator __i)
{ splice_after(__pos, std::move(__list), __i); }
void
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __before, const_iterator __last)
@ -484,6 +493,11 @@ namespace __debug
__before.base(), __last.base());
}
void
splice_after(const_iterator __pos, forward_list& __list,
const_iterator __before, const_iterator __last)
{ splice_after(__pos, std::move(__list), __before, __last); }
void
remove(const _Tp& __val)
{
@ -565,6 +579,10 @@ namespace __debug
}
}
void
merge(forward_list& __list)
{ merge(std::move(__list)); }
template<typename _Comp>
void
merge(forward_list&& __list, _Comp __comp)
@ -584,6 +602,11 @@ namespace __debug
}
}
template<typename _Comp>
void
merge(forward_list& __list, _Comp __comp)
{ merge(std::move(__list), __comp); }
using _Base::sort;
using _Base::reverse;

View File

@ -0,0 +1,94 @@
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 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 Pred 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/>.
#include <forward_list>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::forward_list<int> fl1(1, 5), fl2(1, 4), fl3(1, 3),
fl4(1, 2), fl5(1, 1), fl6(1, 0);
fl1.splice_after(fl1.before_begin(), fl2);
auto it = fl1.begin();
VERIFY( *it == 4 );
++it;
VERIFY( *it == 5 );
fl3.splice_after(fl3.before_begin(), fl4, fl4.before_begin());
it = fl3.begin();
VERIFY( *it == 2 );
++it;
VERIFY( *it == 3 );
fl5.splice_after(fl5.before_begin(), fl6, fl6.before_begin(), fl6.end());
it = fl5.begin();
VERIFY( *it == 0 );
++it;
VERIFY( *it == 1 );
fl1.merge(fl2);
it = fl1.begin();
VERIFY( *it == 4 );
++it;
VERIFY( *it == 5 );
fl1.merge(fl3, std::less<int>());
it = fl1.begin();
VERIFY( *it == 2 );
++it;
VERIFY( *it == 3 );
++it;
VERIFY( *it == 4 );
++it;
VERIFY( *it == 5 );
}
int main()
{
test01();
return 0;
}

View File

@ -1,6 +1,6 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2012 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
@ -68,7 +68,7 @@ test02()
VERIFY(*befy == 10.0);
++befy;
VERIFY(*befy == 15.0);
VERIFY(*befy == 14.0);
}
// This test verifies the following: