Skip to content
Open
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
4 changes: 3 additions & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -4706,7 +4706,9 @@ namespace ranges {
template <class _Tuple, size_t _Index>
concept _Has_tuple_element =
#if _HAS_CXX23
_Tuple_like<_Tuple> && _Index < tuple_size_v<_Tuple>;
_Tuple_like<_Tuple> && _Index < tuple_size_v<_Tuple> && requires(_Tuple __t) {
{ _STD get<_Index>(__t) } -> convertible_to<const tuple_element_t<_Index, _Tuple>&>;
};
#else // ^^^ _HAS_CXX23 / !_HAS_CXX23 vvv
requires(_Tuple __t) {
typename tuple_size<_Tuple>::type;
Expand Down
26 changes: 26 additions & 0 deletions tests/std/tests/P0896R4_views_elements/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,32 @@ void test_gh_3014() { // COMPILE-ONLY
[[maybe_unused]] decltype(as_const(r).begin()) i = r.begin(); // Check 'iterator(iterator<!Const> i)'
}

// LWG-3797 "elements_view insufficiently constrained"
namespace lwg_3797 {
struct Constifier {
template <class T>
constexpr const T& operator()(const T& t) const noexcept {
return t;
}
};

struct Mover {
template <class T>
constexpr remove_reference_t<T>&& operator()(T&& t) const noexcept {
return static_cast<remove_reference_t<T>&&>(t);
}
};

using MoveOnlySubrange = ranges::subrange<test::iterator<test::input, int>, test::sentinel<int>>;
static_assert(!CanViewElements<vector<MoveOnlySubrange>>);
static_assert(!CanViewElements<decltype(vector<MoveOnlySubrange>{} | views::transform(Constifier{}))>);
static_assert(!CanViewElements<decltype(vector<MoveOnlySubrange>{} | views::transform(Mover{}))>);
#if _HAS_CXX23
static_assert(!CanViewElements<decltype(vector<MoveOnlySubrange>{} | views::as_const)>);
static_assert(!CanViewElements<decltype(vector<MoveOnlySubrange>{} | views::as_rvalue)>);
#endif // _HAS_CXX23
} // namespace lwg_3797

int main() {
{ // Validate copyable views
constexpr span<const P> s{some_pairs};
Expand Down