Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of arrays in two-argument ranges::distance #2500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -2843,16 +2843,16 @@ namespace ranges {
using _Not_quite_object::_Not_quite_object;

// clang-format off
template <input_or_output_iterator _It, sentinel_for<_It> _Se>
template <class _It, sentinel_for<_It> _Se>
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
requires (!sized_sentinel_for<_Se, _It>)
_NODISCARD constexpr iter_difference_t<_It> operator()(_It _First, _Se _Last) const {
// clang-format on
_Adl_verify_range(_First, _Last);
return _Distance_unchecked(_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last)));
}

template <input_or_output_iterator _It, sized_sentinel_for<_It> _Se>
_NODISCARD constexpr iter_difference_t<_It> operator()(const _It& _First, const _Se& _Last) const
template <class _It, sized_sentinel_for<decay_t<_It>> _Se>
_NODISCARD constexpr iter_difference_t<_It> operator()(const _It& _First, _Se _Last) const
noexcept(noexcept(_Last - _First)) /* strengthened */ {
return _Last - _First;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3474,9 +3474,19 @@ namespace vso1121031 {
STATIC_ASSERT(!has_member_value_type<indirectly_readable_traits<iterish<float const volatile>>>);
} // namespace vso1121031

constexpr bool test_lwg_XXX() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to annotate (here and in the header) with the proper issue number before merging.

int a[3] = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add another const array for my paranoia

assert(ranges::distance(a, a + 3) == 3);
assert(ranges::distance(a + 3, a) == -3);
return true;
}

int main() {
iterator_cust_swap_test::test();
iter_ops::test();
reverse_iterator_test::test();
move_iterator_test::test();

test_lwg_XXX();
STATIC_ASSERT(test_lwg_XXX());
}