Commit d70e9d81 by Chris Jefferson Committed by Paolo Carlini

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
parent 29b74761
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> 2007-10-11 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/33734 PR libstdc++/33734
......
...@@ -1628,13 +1628,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1628,13 +1628,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_RandomAccessIterator __middle, _RandomAccessIterator __middle,
_RandomAccessIterator __last) _RandomAccessIterator __last)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
std::make_heap(__first, __middle); std::make_heap(__first, __middle);
for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
if (*__i < *__first) 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) ...@@ -1648,13 +1645,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_RandomAccessIterator __middle, _RandomAccessIterator __middle,
_RandomAccessIterator __last, _Compare __comp) _RandomAccessIterator __last, _Compare __comp)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
std::make_heap(__first, __middle, __comp); std::make_heap(__first, __middle, __comp);
for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
if (__comp(*__i, *__first)) if (__comp(*__i, *__first))
std::__pop_heap(__first, __middle, __i, _ValueType(*__i), __comp); std::__pop_heap(__first, __middle, __i, __comp);
} }
// partial_sort // partial_sort
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#define _STL_HEAP_H 1 #define _STL_HEAP_H 1
#include <debug/debug.h> #include <debug/debug.h>
#include <bits/stl_move.h>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
...@@ -121,11 +122,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -121,11 +122,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Distance __parent = (__holeIndex - 1) / 2; _Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __value) while (__holeIndex > __topIndex && *(__first + __parent) < __value)
{ {
*(__first + __holeIndex) = *(__first + __parent); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __parent));
__holeIndex = __parent; __holeIndex = __parent;
__parent = (__holeIndex - 1) / 2; __parent = (__holeIndex - 1) / 2;
} }
*(__first + __holeIndex) = __value; *(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
} }
/** /**
...@@ -153,12 +154,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -153,12 +154,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap(__first, __last - 1); __glibcxx_requires_heap(__first, __last - 1);
_ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
std::__push_heap(__first, _DistanceType((__last - __first) - 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, template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
typename _Compare> typename _Compare>
void void
__push_heap(_RandomAccessIterator __first, _Distance __holeIndex, __push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __topIndex, _Tp __value, _Compare __comp) _Distance __topIndex, _Tp __value, _Compare __comp)
...@@ -167,11 +169,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -167,11 +169,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__holeIndex > __topIndex while (__holeIndex > __topIndex
&& __comp(*(__first + __parent), __value)) && __comp(*(__first + __parent), __value))
{ {
*(__first + __holeIndex) = *(__first + __parent); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __parent));
__holeIndex = __parent; __holeIndex = __parent;
__parent = (__holeIndex - 1) / 2; __parent = (__holeIndex - 1) / 2;
} }
*(__first + __holeIndex) = __value; *(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
} }
/** /**
...@@ -201,8 +203,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -201,8 +203,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last - 1, __comp); __glibcxx_requires_heap_pred(__first, __last - 1, __comp);
_ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
std::__push_heap(__first, _DistanceType((__last - __first) - 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> template<typename _RandomAccessIterator, typename _Distance, typename _Tp>
...@@ -217,28 +220,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -217,28 +220,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__secondChild = 2 * (__secondChild + 1); __secondChild = 2 * (__secondChild + 1);
if (*(__first + __secondChild) < *(__first + (__secondChild - 1))) if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
__secondChild--; __secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
__holeIndex = __secondChild; __holeIndex = __secondChild;
} }
if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2) if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2)
{ {
__secondChild = 2 * (__secondChild + 1); __secondChild = 2 * (__secondChild + 1);
*(__first + __holeIndex) = *(__first + (__secondChild - 1)); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
+ (__secondChild - 1)));
__holeIndex = __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 inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, __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 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance; _DistanceType;
*__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first), _ValueType __value = _GLIBCXX_MOVE(*__result);
__value); *__result = _GLIBCXX_MOVE(*__first);
std::__adjust_heap(__first, _DistanceType(0),
_DistanceType(__last - __first),
_GLIBCXX_MOVE(__value));
} }
/** /**
...@@ -264,8 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -264,8 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap(__first, __last); __glibcxx_requires_heap(__first, __last);
std::__pop_heap(__first, __last - 1, __last - 1, std::__pop_heap(__first, __last - 1, __last - 1);
_ValueType(*(__last - 1)));
} }
template<typename _RandomAccessIterator, typename _Distance, template<typename _RandomAccessIterator, typename _Distance,
...@@ -282,28 +291,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -282,28 +291,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
if (__comp(*(__first + __secondChild), if (__comp(*(__first + __secondChild),
*(__first + (__secondChild - 1)))) *(__first + (__secondChild - 1))))
__secondChild--; __secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
__holeIndex = __secondChild; __holeIndex = __secondChild;
} }
if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2) if ((__len & 1) == 0 && __secondChild == (__len - 2) / 2)
{ {
__secondChild = 2 * (__secondChild + 1); __secondChild = 2 * (__secondChild + 1);
*(__first + __holeIndex) = *(__first + (__secondChild - 1)); *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
+ (__secondChild - 1)));
__holeIndex = __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 inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, __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 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance; _DistanceType;
*__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first), _ValueType __value = _GLIBCXX_MOVE(*__result);
__value, __comp); *__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) ...@@ -322,17 +338,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
pop_heap(_RandomAccessIterator __first, pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp) _RandomAccessIterator __last, _Compare __comp)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements // concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>) _RandomAccessIterator>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last, __comp); __glibcxx_requires_heap_pred(__first, __last, __comp);
std::__pop_heap(__first, __last - 1, __last - 1, std::__pop_heap(__first, __last - 1, __last - 1, __comp);
_ValueType(*(__last - 1)), __comp);
} }
/** /**
...@@ -365,8 +377,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -365,8 +377,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_DistanceType __parent = (__len - 2) / 2; _DistanceType __parent = (__len - 2) / 2;
while (true) while (true)
{ {
std::__adjust_heap(__first, __parent, __len, _ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
_ValueType(*(__first + __parent))); std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value));
if (__parent == 0) if (__parent == 0)
return; return;
__parent--; __parent--;
...@@ -405,8 +417,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -405,8 +417,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_DistanceType __parent = (__len - 2) / 2; _DistanceType __parent = (__len - 2) / 2;
while (true) while (true)
{ {
std::__adjust_heap(__first, __parent, __len, _ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
_ValueType(*(__first + __parent)), __comp); std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
__comp);
if (__parent == 0) if (__parent == 0)
return; return;
__parent--; __parent--;
......
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 Free Software Foundation, Inc. // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
......
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 Free Software Foundation, Inc. // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
......
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