co_return
statement [stmt.return.coroutine]We DO NOT need to inline the body of the coroutine or the algorithm
accumulate
, unless the iterator type retains a pointer or reference to thegenerator<int>
object.Note that authors of coroutine types should be aware of this point: at least one blogger has described an implementation of
generator<T>::iterator
that holds agenerator<T>*
. However, every implementation ofgenerator<T>
we can find in the wild holds acoroutine_handle<Promise>
instead, which avoids the problem, and allows heap allocation elision without inlining accumulate.