diff options
13 files changed, 106 insertions, 13 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index 91cca5c053a..b90f33c6c85 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -3117,10 +3117,10 @@ _SampleIterator __sample(_PopulationIterator __first, input_iterator_tag) { _Distance __k = 0; - for (; __first != __last && __k < __n; ++__first, (void)++__k) + for (; __first != __last && __k < __n; ++__first, (void) ++__k) __output_iter[__k] = *__first; _Distance __sz = __k; - for (; __first != __last; ++__first, (void)++__k) { + for (; __first != __last; ++__first, (void) ++__k) { _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); if (__r < __sz) __output_iter[__r] = *__first; @@ -3190,7 +3190,7 @@ template<class _RandomAccessIterator, class _UniformRandomNumberGenerator> if (__d > 1) { _Dp __uid; - for (--__last, --__d; __first < __last; ++__first, --__d) + for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) { difference_type __i = __uid(__g, _Pp(0, __d)); if (__i != difference_type(0)) @@ -3373,7 +3373,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false __i = __first; - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; @@ -3505,7 +3505,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last __i = ++__first; // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; @@ -4428,14 +4428,14 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator if (__len1 <= __len2) { value_type* __p = __buff; - for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p) + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) ::new(__p) value_type(_VSTD::move(*__i)); __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); } else { value_type* __p = __buff; - for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p) + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) ::new(__p) value_type(_VSTD::move(*__i)); typedef reverse_iterator<_BidirectionalIterator> _RBi; typedef reverse_iterator<value_type*> _Rv; @@ -4575,14 +4575,14 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, { if (__first1 == __last1) { - for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) + for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first2)); __h.release(); return; } if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0)) + for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first1)); __h.release(); return; @@ -4612,7 +4612,7 @@ __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, { if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, ++__result) + for (; __first1 != __last1; ++__first1, (void) ++__result) *__result = _VSTD::move(*__first1); return; } @@ -4627,7 +4627,7 @@ __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, ++__first1; } } - for (; __first2 != __last2; ++__first2, ++__result) + for (; __first2 != __last2; ++__first2, (void) ++__result) *__result = _VSTD::move(*__first2); } @@ -4995,7 +4995,7 @@ void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - for (difference_type __n = __last - __first; __n > 1; --__last, --__n) + for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n) __pop_heap<_Compare>(__first, __last, __comp, __n); } @@ -5065,7 +5065,7 @@ __partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __r = __result_first; if (__r != __result_last) { - for (; __first != __last && __r != __result_last; (void) ++__first, ++__r) + for (; __first != __last && __r != __result_last; ++__first, (void) ++__r) *__r = *__first; __make_heap<_Compare>(__result_first, __r, __comp); typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp index 14b1d1754f2..8ccff2ebb53 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" #if TEST_STD_VER > 17 TEST_CONSTEXPR bool test_constexpr() { @@ -29,9 +30,13 @@ TEST_CONSTEXPR bool test_constexpr() { void test() { + typedef random_access_iterator<int *> RI; int i1[] = {0, 0}; assert(std::is_heap(i1, i1)); assert(std::is_heap(i1, i1+1) == (std::is_heap_until(i1, i1+1) == i1+1)); + assert(std::is_heap(RI(i1), RI(i1))); + assert(std::is_heap(RI(i1), RI(i1+1)) == (std::is_heap_until(RI(i1), RI(i1+1)) == RI(i1+1))); + int i2[] = {0, 1}; int i3[] = {1, 0}; assert(std::is_heap(i1, i1+2) == (std::is_heap_until(i1, i1+2) == i1+2)); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp index 9e344588239..b07a3c8f24f 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" #if TEST_STD_VER > 17 TEST_CONSTEXPR bool test_constexpr() { @@ -30,9 +31,13 @@ TEST_CONSTEXPR bool test_constexpr() { void test() { + typedef random_access_iterator<int *> RI; int i1[] = {0, 0}; assert(std::is_heap(i1, i1, std::greater<int>())); assert(std::is_heap(i1, i1+1, std::greater<int>()) == (std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1)); + assert(std::is_heap(RI(i1), RI(i1), std::greater<int>())); + assert(std::is_heap(RI(i1), RI(i1+1), std::greater<int>()) == (std::is_heap_until(RI(i1), RI(i1+1), std::greater<int>()) == RI(i1+1))); + int i2[] = {0, 1}; int i3[] = {1, 0}; assert(std::is_heap(i1, i1+2, std::greater<int>()) == (std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2)); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp index b9bb3e1f5bf..9708db7ce5f 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" #if TEST_STD_VER > 17 TEST_CONSTEXPR bool test_constexpr() { @@ -29,9 +30,13 @@ TEST_CONSTEXPR bool test_constexpr() { void test() { + typedef random_access_iterator<int *> RI; int i1[] = {0, 0}; assert(std::is_heap_until(i1, i1) == i1); assert(std::is_heap_until(i1, i1+1) == i1+1); + assert(std::is_heap_until(RI(i1), RI(i1)) == RI(i1)); + assert(std::is_heap_until(RI(i1), RI(i1+1)) == RI(i1+1)); + int i2[] = {0, 1}; int i3[] = {1, 0}; assert(std::is_heap_until(i1, i1+2) == i1+2); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp index 6002f662e1a..1cec5440f00 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" #if TEST_STD_VER > 17 TEST_CONSTEXPR bool test_constexpr() { @@ -30,9 +31,13 @@ TEST_CONSTEXPR bool test_constexpr() { void test() { + typedef random_access_iterator<int *> RI; int i1[] = {0, 0}; assert(std::is_heap_until(i1, i1, std::greater<int>()) == i1); assert(std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1); + assert(std::is_heap_until(RI(i1), RI(i1), std::greater<int>()) == RI(i1)); + assert(std::is_heap_until(RI(i1), RI(i1+1), std::greater<int>()) == RI(i1+1)); + int i2[] = {0, 1}; int i3[] = {1, 0}; assert(std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp index 76244a9f0b3..80422998c47 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" std::mt19937 randomness; @@ -29,6 +30,12 @@ void test(int N) std::shuffle(ia, ia+N, randomness); std::make_heap(ia, ia+N); assert(std::is_heap(ia, ia+N)); + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + std::make_heap(RI(ia), RI(ia+N)); + assert(std::is_heap(RI(ia), RI(ia+N))); + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp index 0650f745479..23c501cd774 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp @@ -21,6 +21,7 @@ #include "test_macros.h" #include "counting_predicates.hpp" +#include "test_iterators.h" struct indirect_less { @@ -40,6 +41,11 @@ void test(int N) std::shuffle(ia, ia+N, randomness); std::make_heap(ia, ia+N, std::greater<int>()); assert(std::is_heap(ia, ia+N, std::greater<int>())); + + std::shuffle(ia, ia+N, randomness); + std::make_heap(random_access_iterator<int *>(ia), + random_access_iterator<int *>(ia+N), std::greater<int>()); + assert(std::is_heap(ia, ia+N, std::greater<int>())); } // Ascending diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp index fa0e1120b30..1282232e477 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" std::mt19937 randomness; @@ -34,6 +35,18 @@ void test(int N) assert(std::is_heap(ia, ia+i-1)); } std::pop_heap(ia, ia); + + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + std::make_heap(RI(ia), RI(ia+N)); + for (int i = N; i > 0; --i) + { + std::pop_heap(RI(ia), RI(ia+i)); + assert(std::is_heap(RI(ia), RI(ia+i-1))); + } + std::pop_heap(RI(ia), RI(ia)); + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp index 63bd1520f46..dc4658ff0c1 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp @@ -20,6 +20,7 @@ #include <memory> #include "test_macros.h" +#include "test_iterators.h" struct indirect_less { @@ -44,6 +45,17 @@ void test(int N) assert(std::is_heap(ia, ia+i-1, std::greater<int>())); } std::pop_heap(ia, ia, std::greater<int>()); + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + std::make_heap(RI(ia), RI(ia+N), std::greater<int>()); + for (int i = N; i > 0; --i) + { + std::pop_heap(RI(ia), RI(ia+i), std::greater<int>()); + assert(std::is_heap(RI(ia), RI(ia+i-1), std::greater<int>())); + } + std::pop_heap(RI(ia), RI(ia), std::greater<int>()); + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp index 208bf6e80f5..52f279bac6e 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp @@ -19,6 +19,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" std::mt19937 randomness; @@ -33,6 +34,15 @@ void test(int N) std::push_heap(ia, ia+i); assert(std::is_heap(ia, ia+i)); } + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + for (int i = 0; i <= N; ++i) + { + std::push_heap(RI(ia), RI(ia+i)); + assert(std::is_heap(RI(ia), RI(ia+i))); + } + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp index 4a47f65bfc3..3681d87c5b5 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp @@ -21,6 +21,7 @@ #include <memory> #include "test_macros.h" +#include "test_iterators.h" struct indirect_less { @@ -42,6 +43,15 @@ void test(int N) std::push_heap(ia, ia+i, std::greater<int>()); assert(std::is_heap(ia, ia+i, std::greater<int>())); } + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + for (int i = 0; i <= N; ++i) + { + std::push_heap(RI(ia), RI(ia+i), std::greater<int>()); + assert(std::is_heap(RI(ia), RI(ia+i), std::greater<int>())); + } + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp index 7d48b87aea5..30ef3456065 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_macros.h" +#include "test_iterators.h" std::mt19937 randomness; @@ -30,6 +31,13 @@ void test(int N) std::make_heap(ia, ia+N); std::sort_heap(ia, ia+N); assert(std::is_sorted(ia, ia+N)); + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + std::make_heap(RI(ia), RI(ia+N)); + std::sort_heap(RI(ia), RI(ia+N)); + assert(std::is_sorted(RI(ia), RI(ia+N))); + delete [] ia; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp index 151373b7181..df791f2de4a 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp @@ -20,6 +20,7 @@ #include <memory> #include "test_macros.h" +#include "test_iterators.h" struct indirect_less { @@ -39,6 +40,12 @@ void test(int N) std::make_heap(ia, ia+N, std::greater<int>()); std::sort_heap(ia, ia+N, std::greater<int>()); assert(std::is_sorted(ia, ia+N, std::greater<int>())); + + typedef random_access_iterator<int *> RI; + std::shuffle(RI(ia), RI(ia+N), randomness); + std::make_heap(RI(ia), RI(ia+N), std::greater<int>()); + std::sort_heap(RI(ia), RI(ia+N), std::greater<int>()); + assert(std::is_sorted(RI(ia), RI(ia+N), std::greater<int>())); delete [] ia; } |