This was approved in Wrocław as LWG 3899. libstdc++-v3/ChangeLog:
* include/std/generator (generator::yield_value): Add overload taking lvalue element_of view, as per LWG 3899. --- The issue suggests that this change avoids creating a new coroutine frame, so I thought if I used a custom allocator I'd be able to see a reduction in memory allocation after this fix. I was unable to see any difference. I would welcome a testcase for it. Tested x86_64-linux. libstdc++-v3/include/std/generator | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libstdc++-v3/include/std/generator b/libstdc++-v3/include/std/generator index bba85bd0aa4..807e724c0c8 100644 --- a/libstdc++-v3/include/std/generator +++ b/libstdc++-v3/include/std/generator @@ -153,6 +153,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept { return _Recursive_awaiter { std::move(__r.range) }; } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3899. co_yielding elements of an lvalue generator is + // unnecessarily inefficient + template<typename _R2, typename _V2, typename _A2, typename _U2> + requires std::same_as<_Yield2_t<_R2, _V2>, _Yielded> + auto + yield_value(ranges::elements_of<generator<_R2, _V2, _A2>&, _U2> __r) + noexcept + { return _Recursive_awaiter { std::move(__r.range) }; } + template<ranges::input_range _R, typename _Alloc> requires convertible_to<ranges::range_reference_t<_R>, _Yielded> auto -- 2.47.1