diff --git a/libcxx/include/__algorithm/copy_n.h b/libcxx/include/__algorithm/copy_n.h --- a/libcxx/include/__algorithm/copy_n.h +++ b/libcxx/include/__algorithm/copy_n.h @@ -57,9 +57,10 @@ >::type copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator>::difference_type difference_type; typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize; _IntegralSize __n = __orig_n; - return _VSTD::copy(__first, __first + __n, __result); + return _VSTD::copy(__first, __first + difference_type(__n), __result); } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/find_end.h b/libcxx/include/__algorithm/find_end.h --- a/libcxx/include/__algorithm/find_end.h +++ b/libcxx/include/__algorithm/find_end.h @@ -95,14 +95,16 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end( _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) { + typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; + typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2; + _D2 __len2 = __last2 - __first2; if (__len2 == 0) return __last1; - typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1; + _D1 __len1 = __last1 - __first1; if (__len1 < __len2) return __last1; - const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here + const _RandomAccessIterator1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here _RandomAccessIterator1 __l1 = __last1; _RandomAccessIterator2 __l2 = __last2; --__l2; diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h --- a/libcxx/include/__algorithm/search.h +++ b/libcxx/include/__algorithm/search.h @@ -68,7 +68,7 @@ const _D1 __len1 = __last1 - __first1; if (__len1 < __len2) return _VSTD::make_pair(__last1, __last1); - const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + const _RandomAccessIterator1 __s = __last1 - _D1(__len2 - 1); // Start of pattern match can't go beyond here while (true) { while (true) { @@ -83,7 +83,7 @@ _RandomAccessIterator2 __m2 = __first2; while (true) { if (++__m2 == __last2) - return _VSTD::make_pair(__first1, __first1 + __len2); + return _VSTD::make_pair(__first1, __first1 + _D1(__len2)); ++__m1; // no need to check range on __m1 because __s guarantees we have enough source if (!__pred(*__m1, *__m2)) { ++__first1; diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h --- a/libcxx/include/__algorithm/search_n.h +++ b/libcxx/include/__algorithm/search_n.h @@ -59,12 +59,13 @@ _RandomAccessIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag) { + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; if (__count <= 0) return __first; _Size __len = static_cast<_Size>(__last - __first); if (__len < __count) return __last; - const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here + const _RandomAccessIterator __s = __last - difference_type(__count - 1); // Start of pattern match can't go beyond here while (true) { // Find first element in sequence that matchs __value_, with a mininum of loop checks while (true) { diff --git a/libcxx/include/__algorithm/sift_down.h b/libcxx/include/__algorithm/sift_down.h --- a/libcxx/include/__algorithm/sift_down.h +++ b/libcxx/include/__algorithm/sift_down.h @@ -38,7 +38,7 @@ __child = 2 * __child + 1; _RandomAccessIterator __child_i = __first + __child; - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { + if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { // right-child exists and is greater than left-child ++__child_i; ++__child; @@ -63,7 +63,7 @@ __child = 2 * __child + 1; __child_i = __first + __child; - if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { + if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) { // right-child exists and is greater than left-child ++__child_i; ++__child; diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h --- a/libcxx/include/__algorithm/sort.h +++ b/libcxx/include/__algorithm/sort.h @@ -160,10 +160,11 @@ void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first+2; - _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp); - for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + _RandomAccessIterator __j = __first+difference_type(2); + _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp); + for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i) { if (__comp(*__i, *__j)) { @@ -185,6 +186,7 @@ bool __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; switch (__last - __first) { case 0: @@ -195,21 +197,21 @@ swap(*__first, *__last); return true; case 3: - _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp); return true; case 4: - _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp); return true; case 5: - _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp); return true; } typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first+2; - _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp); + _RandomAccessIterator __j = __first+difference_type(2); + _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp); const unsigned __limit = 8; unsigned __count = 0; - for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i) { if (__comp(*__i, *__j)) { @@ -288,13 +290,13 @@ swap(*__first, *__last); return; case 3: - _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); + _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp); return; case 4: - _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); + _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp); return; case 5: - _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); + _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp); return; } if (__len <= __limit) @@ -433,7 +435,7 @@ if (__n_swaps == 0) { bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); - if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) + if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+difference_type(1), __last, __comp)) { if (__fs) return; @@ -457,7 +459,7 @@ } else { - _VSTD::__introsort<_Compare>(__i + 1, __last, __comp, __depth); + _VSTD::__introsort<_Compare>(__i + difference_type(1), __last, __comp, __depth); __last = __i; } } diff --git a/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp b/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp --- a/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp +++ b/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp @@ -78,6 +78,7 @@ auto mid = PickyIterator(a+5); auto last = PickyIterator(a+10); auto first2 = PickyIterator(b); + auto mid2 = PickyIterator(b+5); auto last2 = PickyIterator(b+10); void *value = nullptr; int count = 1; @@ -96,7 +97,7 @@ #endif (void)std::copy(first, last, first2); (void)std::copy_backward(first, last, last2); - // TODO FIXME (void)std::copy_n(first, count, first2); + (void)std::copy_n(first, count, first2); (void)std::count(first, last, value); (void)std::count_if(first, last, UnaryTrue()); (void)std::distance(first, last); @@ -111,8 +112,8 @@ (void)std::fill(first, last, value); (void)std::fill_n(first, count, value); (void)std::find(first, last, value); - // TODO FIXME (void)std::find_end(first, last, first2, mid2); - // TODO FIXME (void)std::find_end(first, last, first2, mid2, std::equal_to()); + (void)std::find_end(first, last, first2, mid2); + (void)std::find_end(first, last, first2, mid2, std::equal_to()); (void)std::find_if(first, last, UnaryTrue()); (void)std::find_if_not(first, last, UnaryTrue()); (void)std::for_each(first, last, UnaryVoid()); @@ -146,8 +147,8 @@ // TODO: lexicographical_compare_three_way (void)std::lower_bound(first, last, value); (void)std::lower_bound(first, last, value, std::less()); - // TODO FIXME (void)std::make_heap(first, last); - // TODO FIXME (void)std::make_heap(first, last, std::less()); + (void)std::make_heap(first, last); + (void)std::make_heap(first, last, std::less()); (void)std::max(value, value); (void)std::max(value, value, std::less()); #if TEST_STD_VER >= 11 @@ -187,15 +188,15 @@ (void)std::none_of(first, last, UnaryTrue()); (void)std::nth_element(first, mid, last); (void)std::nth_element(first, mid, last, std::less()); - // TODO FIXME (void)std::partial_sort(first, mid, last); - // TODO FIXME (void)std::partial_sort(first, mid, last, std::less()); - // TODO FIXME (void)std::partial_sort_copy(first, last, first2, mid2); - // TODO FIXME (void)std::partial_sort_copy(first, last, first2, mid2, std::less()); + (void)std::partial_sort(first, mid, last); + (void)std::partial_sort(first, mid, last, std::less()); + (void)std::partial_sort_copy(first, last, first2, mid2); + (void)std::partial_sort_copy(first, last, first2, mid2, std::less()); (void)std::partition(first, last, UnaryTrue()); (void)std::partition_copy(first, last, first2, last2, UnaryTrue()); (void)std::partition_point(first, last, UnaryTrue()); - // TODO FIXME (void)std::pop_heap(first, last); - // TODO FIXME (void)std::pop_heap(first, last, std::less()); + (void)std::pop_heap(first, last); + (void)std::pop_heap(first, last, std::less()); (void)std::prev_permutation(first, last); (void)std::prev_permutation(first, last, std::less()); (void)std::push_heap(first, last); @@ -212,10 +213,10 @@ (void)std::reverse_copy(first, last, first2); (void)std::rotate(first, mid, last); (void)std::rotate_copy(first, mid, last, first2); - // TODO FIXME (void)std::search(first, last, first2, mid2); - // TODO FIXME (void)std::search(first, last, first2, mid2, std::equal_to()); - // TODO FIXME (void)std::search_n(first, last, count, value); - // TODO FIXME (void)std::search_n(first, last, count, value, std::equal_to()); + (void)std::search(first, last, first2, mid2); + (void)std::search(first, last, first2, mid2, std::equal_to()); + (void)std::search_n(first, last, count, value); + (void)std::search_n(first, last, count, value, std::equal_to()); (void)std::set_difference(first, mid, mid, last, first2); (void)std::set_difference(first, mid, mid, last, first2, std::less()); (void)std::set_intersection(first, mid, mid, last, first2); @@ -228,10 +229,10 @@ (void)std::shift_left(first, last, count); (void)std::shift_right(first, last, count); #endif - // TODO FIXME (void)std::sort(first, last); - // TODO FIXME (void)std::sort(first, last, std::less()); - // TODO FIXME (void)std::sort_heap(first, last); - // TODO FIXME (void)std::sort_heap(first, last, std::less()); + (void)std::sort(first, last); + (void)std::sort(first, last, std::less()); + (void)std::sort_heap(first, last); + (void)std::sort_heap(first, last, std::less()); if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_partition(first, last, UnaryTrue()); if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_sort(first, last); if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_sort(first, last, std::less());