Subject: Re: [std-proposals] defect report: coexisting return_value and return_void in coroutines
From: Jason McKesson (jmckesson_at_[hidden])
Date: 2020-10-11 10:22:33
It seems to me that what you want is the equivalent of a proper tail
call for coroutines. That's a valid thing to want.
But you shouldn't co-opt a mechanism like `return_value` to gain this
functionality just because it's convenient. C++ doesn't let you use
`return <expr>` unless your function actually returns that value. The
same ought to be true of `co_return <expr>`. If your coroutine is not
actually returning the result of `<expr>`, then you shouldn't express
it as `co_return`. And if your promise has a `return_value` function,
then that function ought to do what it says: return a value of that
type through its future.
Let's not take mechanisms and make them do weird things just because
it's convenient. You can build what you want without a new keyword
just by employing a bit of indirection:
Where `tail_continue` is a type that stores the future returned by
`yet_another`. `co_await`ing on it will not suspend execution.
Instead, it does what your hypothetical call to `return_value` would
do: change the promise to use the given future.
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups