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-4083 views::as_rvalue should reject non-input ranges #4786

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 5 additions & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -1524,15 +1524,19 @@ namespace ranges {

namespace views {
template <class _Rng>
#ifdef __EDG__ // TRANSITION, DevCom-10698021
concept _Can_as_rvalue = requires(_Rng&& __r) { as_rvalue_view(static_cast<_Rng&&>(__r)); };
#else // ^^^ workaround / no workaround vvv
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
concept _Can_as_rvalue = requires(_Rng&& __r) { as_rvalue_view{static_cast<_Rng&&>(__r)}; };
#endif // ^^^ no workaround ^^^

class _As_rvalue_fn : public _Pipe::_Base<_As_rvalue_fn> {
private:
enum class _St { _None, _All, _As_rvalue };

template <class _Rng>
_NODISCARD static consteval _Choice_t<_St> _Choose() noexcept {
if constexpr (same_as<range_rvalue_reference_t<_Rng>, range_reference_t<_Rng>>) {
if constexpr (input_range<_Rng> && same_as<range_rvalue_reference_t<_Rng>, range_reference_t<_Rng>>) {
return {_St::_All, noexcept(views::all(_STD declval<_Rng>()))};
} else if constexpr (_Can_as_rvalue<_Rng>) {
return {_St::_As_rvalue, noexcept(as_rvalue_view{_STD declval<_Rng>()})};
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
11 changes: 11 additions & 0 deletions tests/std/tests/P2446R2_views_as_rvalue/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ void test_example_from_p2446r2() {
assert(ranges::all_of(words, ranges::empty)); // all strings from words are empty (implementation assumption)
}

// LWG-4083 "views::as_rvalue should reject non-input ranges"
struct OutputRvalueIterator {
using difference_type = int;
int operator*() const;
OutputRvalueIterator& operator++();
void operator++(int);
};
using OutputRvalueRange = decltype(ranges::subrange{OutputRvalueIterator{}, unreachable_sentinel});

static_assert(!CanViewAsRvalue<OutputRvalueRange>);
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved

int main() {
{ // Validate views
// ... copyable
Expand Down