This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.
4119.generator::promise_type::yield_value(ranges::elements_of<R, Alloc>)
's nested generator
may be ill-formed
Section: 25.8.5 [coro.generator.promise] Status: WP Submitter: Hewill Kang Opened: 2024-07-11 Last modified: 2024-11-28
Priority: Not Prioritized
View all other issues in [coro.generator.promise].
View all issues with WP status.
Discussion:
The nested coroutine is specified to return generator<yielded, ranges::range_value_t<R>, Alloc>
which can be problematic as the value type of R
is really irrelevant to yielded
, unnecessarily violating the generator
's Mandates (demo):
#include <generator> #include <vector> std::generator<std::span<int>> f() { std::vector<int> v; co_yield v; // ok } std::generator<std::span<int>> g() { std::vector<std::vector<int>> v; co_yield std::ranges::elements_of(v); // hard error }
This proposed resolution is to change the second template parameter from range_value_t<R>
to void
since that type doesn't matter to us.
[2024-08-02; Reflector poll]
Set status to Tentatively Ready after five votes in favour during reflector poll.
[Wrocław 2024-11-23; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4986.
Modify 25.8.5 [coro.generator.promise] as indicated:
template<ranges::input_range R, class Alloc> requires convertible_to<ranges::range_reference_t<R>, yielded> auto yield_value(ranges::elements_of<R, Alloc> r);-13- Effects: Equivalent to:
[…]auto nested = [](allocator_arg_t, Alloc, ranges::iterator_t<R> i, ranges::sentinel_t<R> s) -> generator<yielded, ranges::range_value_t<R>void, Alloc> { for (; i != s; ++i) { co_yield static_cast<yielded>(*i); } }; return yield_value(ranges::elements_of(nested( allocator_arg, r.allocator, ranges::begin(r.range), ranges::end(r.range))));
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4