On Wed, Jan 20, 2021 at 9:21 AM Omry Noam via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
What if we specialized a function template templated on bool, to have one version that's a coroutine, and one version that's a normal function?
Maybe something like: https://godbolt.org/z/7TEnb6
(Code adapted from cppreference as an example)

I believe that's well-formed, but I'm pretty sure OP's main goal is to avoid writing the code twice.

I do agree that it would be useful if Chuanqi provided a more fleshed-out and realistic example. When the body of the function is only one line, it's easy to say "just write it twice." If the function were more complicated, it would be more obvious why "write everything twice" wouldn't be an acceptable solution.
But I personally can't come up with such an example off the top of my head; I'm not good enough at coroutine stuff.