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

Implement LWG-3420 #786

Merged
merged 3 commits into from
May 5, 2020
Merged
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
12 changes: 7 additions & 5 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,13 @@ struct _Iter_traits_difference<false> {

// clang-format off
template <class _It>
concept _Cpp17_iterator = copyable<_It> && requires(_It __i) {
{ *__i } -> _Can_reference;
{ ++__i } -> same_as<_It&>;
{ *__i++ } -> _Can_reference;
};
concept _Cpp17_iterator = // per LWG-3420
requires(_It __i) {
{ *__i } -> _Can_reference;
{ ++__i } -> same_as<_It&>;
{ *__i++ } -> _Can_reference;
}
&& copyable<_It>;

template <class _It>
concept _Cpp17_input_iterator = _Cpp17_iterator<_It>
Expand Down
14 changes: 14 additions & 0 deletions tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,20 @@ namespace reverse_iterator_test {
!std::sized_sentinel_for<reverse_iterator<simple_no_difference>, reverse_iterator<simple_no_difference>>);
} // namespace reverse_iterator_test

namespace lwg3420 {
// Validate that we can ask for the iterator_traits of a type with no operator* for which checking copyability
// results in constraint recursion.
struct X {
X() = default;
template <std::copyable T>
X(T const&);
};
STATIC_ASSERT(!has_member_iter_concept<std::iterator_traits<X>>);
STATIC_ASSERT(!has_member_iter_category<std::iterator_traits<X>>);
STATIC_ASSERT(!has_member_difference_type<std::iterator_traits<X>>);
STATIC_ASSERT(!has_member_value_type<std::iterator_traits<X>>);
} // namespace lwg3420

int main() {
iterator_cust_swap_test::test();
iter_ops::test();
Expand Down