Implement LWG-3797 elements_view insufficiently constrained#6310
Open
frederick-vs-ja wants to merge 1 commit into
Open
Implement LWG-3797 elements_view insufficiently constrained#6310frederick-vs-ja wants to merge 1 commit into
elements_view insufficiently constrained#6310frederick-vs-ja wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR implements LWG-3797 "elements_view insufficiently constrained" by adding a missing constraint to the _Has_tuple_element concept in C++23 mode, ensuring that get<N>(t) is convertible to const tuple_element_t<N, T>&. The pre-C++23 path already had this constraint, but it was inadvertently dropped when the C++23 _Tuple_like concept was introduced.
Changes:
- Added the
get<_Index>(__t) -> convertible_to<const tuple_element_t<_Index, _Tuple>&>constraint to the C++23 branch of_Has_tuple_element. - Added compile-only tests verifying that
elements_viewcorrectly rejects ranges whose element type has a move-only component (e.g., subranges with move-only input iterators), covering direct vectors, transformed views,as_const, andas_rvalue.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| stl/inc/ranges | Adds the missing requires constraint for get convertibility to _Has_tuple_element in C++23 mode |
| tests/std/tests/P0896R4_views_elements/test.cpp | Adds compile-time tests for LWG-3797 using move-only subranges and various view adaptors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6204.
However, it seems that
elements_viewbecomes overconstrained with this fix, although it was already overconstrained in C++20. Currently (after LWG-3797) the following code is rejected, while it seems to me that it can be made to work.Seems like that the constraints of
elements_vieware somehow imprecise. Especially,_Has_tuple_elementdoesn't seem to handle rvalues well. IMO, ideally, they should only match validness of iterator'soperator*while additionally requiring tuple-like-ness.