[libc++] Reword std::advance assertion message for consistency with ranges::advance (#138749)
As brought up in https://github.com/llvm/llvm-project/pull/133276.
This commit is contained in:
@@ -66,7 +66,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i
|
||||
typedef typename iterator_traits<_InputIter>::difference_type _Difference;
|
||||
_Difference __n = static_cast<_Difference>(std::__convert_to_integral(__orig_n));
|
||||
_LIBCPP_ASSERT_PEDANTIC(__has_bidirectional_iterator_category<_InputIter>::value || __n >= 0,
|
||||
"Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
|
||||
"std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
|
||||
std::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ int main(int, char**) {
|
||||
forward_iterator<int *> it(a+1);
|
||||
std::advance(it, 1); // should work fine
|
||||
std::advance(it, 0); // should work fine
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::advance(it, -1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::advance(it, -1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ int main(int, char**) {
|
||||
forward_iterator<int *> it(a+1);
|
||||
(void)std::next(it, 1); // should work fine
|
||||
(void)std::next(it, 0); // should work fine
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::next(it, -1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::next(it, -1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ int main(int, char**) {
|
||||
forward_iterator<int *> it(a+1);
|
||||
(void)std::prev(it, -1); // should work fine
|
||||
(void)std::prev(it, 0); // should work fine
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::prev(it, 1), "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
|
||||
TEST_LIBCPP_ASSERT_FAILURE(std::prev(it, 1), "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user