stl_heap.h (__push_heap, [...]): Use _GLIBCXX_MOVE.

2007-10-11  Chris Jefferson  <chris@bubblescope.net>
	    Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
	make_heap): Use _GLIBCXX_MOVE.
	(__pop_heap): Likewise, adjust signature.
	(pop_heap): Adjust __pop_heap call.
	* include/bits/stl_algo.h (__heap_select): Likewise.
	* testsuite/25_algorithms/heap/moveable.cc: Remove dg-require-rvalref.
	* testsuite/25_algorithms/partial_sort/moveable.cc: Likewise.

Co-Authored-By: Paolo Carlini <pcarlini@suse.de>

From-SVN: r129237
This commit is contained in:
Chris Jefferson 2007-10-11 17:56:31 +00:00 committed by Paolo Carlini
parent 29b747611f
commit d70e9d8156
5 changed files with 62 additions and 46 deletions

View File

@ -1,3 +1,14 @@
2007-10-11 Chris Jefferson <chris@bubblescope.net>
Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
make_heap): Use _GLIBCXX_MOVE.
(__pop_heap): Likewise, adjust signature.
(pop_heap): Adjust __pop_heap call.
* include/bits/stl_algo.h (__heap_select): Likewise.
* testsuite/25_algorithms/heap/moveable.cc: Remove dg-require-rvalref.
* testsuite/25_algorithms/partial_sort/moveable.cc: Likewise.
2007-10-11 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/33734

View File

@ -1628,13 +1628,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_RandomAccessIterator __middle,
_RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
std::make_heap(__first, __middle);
for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
if (*__i < *__first)
std::__pop_heap(__first, __middle, __i, _ValueType(*__i));
std::__pop_heap(__first, __middle, __i);
}
/**
@ -1648,13 +1645,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_RandomAccessIterator __middle,
_RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
std::make_heap(__first, __middle, __comp);
for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
if (__comp(*__i, *__first))
std::__pop_heap(__first, __middle, __i, _ValueType(*__i), __comp);
std::__pop_heap(__first, __middle, __i, __comp);
}
// partial_sort

View File

@ -62,6 +62,7 @@
#define _STL_HEAP_H 1
#include <debug/debug.h>
#include <bits/stl_move.h>
_GLIBCXX_BEGIN_NAMESPACE(std)
@ -121,11 +122,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __value)
{
*(__first + __holeIndex) = *(__first + __parent);
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __parent));
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __value;
*(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
}
/**
@ -153,12 +154,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap(__first, __last - 1);
_ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_DistanceType(0), _ValueType(*(__last - 1)));
_DistanceType(0), _GLIBCXX_MOVE(__value));
}
template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
typename _Compare>
typename _Compare>
void
__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __topIndex, _Tp __value, _Compare __comp)
@ -167,11 +169,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__holeIndex > __topIndex
&& __comp(*(__first + __parent), __value))
{
*(__first + __holeIndex) = *(__first + __parent);
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __parent));
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __value;
*(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
}
/**
@ -201,8 +203,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last - 1, __comp);
_ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_DistanceType(0), _ValueType(*(__last - 1)), __comp);
_DistanceType(0), _GLIBCXX_MOVE(__value), __comp);
}
template<typename _RandomAccessIterator, typename _Distance, typename _Tp>
@ -217,28 +220,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__secondChild = 2 * (__secondChild + 1);
if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
__holeIndex = __secondChild;
}
if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2)
{
__secondChild = 2 * (__secondChild + 1);
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
+ (__secondChild - 1)));
__holeIndex = __secondChild - 1;
}
std::__push_heap(__first, __holeIndex, __topIndex, __value);
std::__push_heap(__first, __holeIndex, __topIndex,
_GLIBCXX_MOVE(__value));
}
template<typename _RandomAccessIterator, typename _Tp>
template<typename _RandomAccessIterator>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value)
_RandomAccessIterator __result)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value);
_DistanceType;
_ValueType __value = _GLIBCXX_MOVE(*__result);
*__result = _GLIBCXX_MOVE(*__first);
std::__adjust_heap(__first, _DistanceType(0),
_DistanceType(__last - __first),
_GLIBCXX_MOVE(__value));
}
/**
@ -264,8 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap(__first, __last);
std::__pop_heap(__first, __last - 1, __last - 1,
_ValueType(*(__last - 1)));
std::__pop_heap(__first, __last - 1, __last - 1);
}
template<typename _RandomAccessIterator, typename _Distance,
@ -282,28 +291,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
if (__comp(*(__first + __secondChild),
*(__first + (__secondChild - 1))))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
__holeIndex = __secondChild;
}
if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2)
{
__secondChild = 2 * (__secondChild + 1);
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
*(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
+ (__secondChild - 1)));
__holeIndex = __secondChild - 1;
}
std::__push_heap(__first, __holeIndex, __topIndex, __value, __comp);
std::__push_heap(__first, __holeIndex, __topIndex,
_GLIBCXX_MOVE(__value), __comp);
}
template<typename _RandomAccessIterator, typename _Tp, typename _Compare>
template<typename _RandomAccessIterator, typename _Compare>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value, _Compare __comp)
_RandomAccessIterator __result, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value, __comp);
_DistanceType;
_ValueType __value = _GLIBCXX_MOVE(*__result);
*__result = _GLIBCXX_MOVE(*__first);
std::__adjust_heap(__first, _DistanceType(0),
_DistanceType(__last - __first),
_GLIBCXX_MOVE(__value), __comp);
}
/**
@ -322,17 +338,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>)
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last, __comp);
std::__pop_heap(__first, __last - 1, __last - 1,
_ValueType(*(__last - 1)), __comp);
std::__pop_heap(__first, __last - 1, __last - 1, __comp);
}
/**
@ -365,8 +377,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_DistanceType __parent = (__len - 2) / 2;
while (true)
{
std::__adjust_heap(__first, __parent, __len,
_ValueType(*(__first + __parent)));
_ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value));
if (__parent == 0)
return;
__parent--;
@ -405,8 +417,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_DistanceType __parent = (__len - 2) / 2;
while (true)
{
std::__adjust_heap(__first, __parent, __len,
_ValueType(*(__first + __parent)), __comp);
_ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
__comp);
if (__parent == 0)
return;
__parent--;

View File

@ -1,4 +1,3 @@
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 Free Software Foundation, Inc.

View File

@ -1,4 +1,3 @@
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 Free Software Foundation, Inc.