@@ -65,8 +65,7 @@ template < class _InputIter,
6565_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance (_InputIter& __i, _Distance __orig_n) {
6666 typedef typename iterator_traits<_InputIter>::difference_type _Difference;
6767 _Difference __n = static_cast <_Difference>(std::__convert_to_integral (__orig_n));
68- // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
69- _LIBCPP_ASSERT_PEDANTIC (__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
68+ _LIBCPP_ASSERT_PEDANTIC (__has_bidirectional_iterator_category<_InputIter>::value || __n >= 0 ,
7069 " Attempt to advance(it, n) with negative n on a non-bidirectional iterator" );
7170 std::__advance (__i, __n, typename iterator_traits<_InputIter>::iterator_category ());
7271}
@@ -98,9 +97,8 @@ struct __advance {
9897 // Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
9998 template <input_or_output_iterator _Ip>
10099 _LIBCPP_HIDE_FROM_ABI constexpr void operator ()(_Ip& __i, iter_difference_t <_Ip> __n) const {
101- // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
102- _LIBCPP_ASSERT_PEDANTIC (
103- __n >= 0 || bidirectional_iterator<_Ip>, " If `n < 0`, then `bidirectional_iterator<I>` must be true." );
100+ _LIBCPP_ASSERT_PEDANTIC (bidirectional_iterator<_Ip> || __n >= 0 ,
101+ " ranges::advance: Can only pass a negative `n` with a bidirectional_iterator." );
104102
105103 // If `I` models `random_access_iterator`, equivalent to `i += n`.
106104 if constexpr (random_access_iterator<_Ip>) {
@@ -149,9 +147,9 @@ struct __advance {
149147 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
150148 _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t <_Ip>
151149 operator ()(_Ip& __i, iter_difference_t <_Ip> __n, _Sp __bound_sentinel) const {
152- // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
153- _LIBCPP_ASSERT_PEDANTIC ((__n >= 0 ) || (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>),
154- " If `n < 0`, then ` bidirectional_iterator<I> && same_as<I, S>` must be true ." );
150+ _LIBCPP_ASSERT_PEDANTIC (
151+ (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>) || (__n >= 0 ),
152+ " ranges::advance: Can only pass a negative `n` with a bidirectional_iterator coming from a common_range ." );
155153 // If `S` and `I` model `sized_sentinel_for<S, I>`:
156154 if constexpr (sized_sentinel_for<_Sp, _Ip>) {
157155 // If |n| >= |bound_sentinel - i|, equivalent to `ranges::advance(i, bound_sentinel)`.
0 commit comments