I'd like to make a function with both sync and coroutine version, without using template specialization, i.e. with an if constexpr.
This is the function I wrote:
template <Async _a>
AsyncResult<int, _a> func(int a) {
if constexpr (_a == Async::Disable)
return a;
else
co_return a;
}
But when I instantiate the true branch it gives an error
auto a = func<Async::Disable>(1); // compiler error
auto b = func<Async::Enable>(2); // ok
error: unable to find the promise type for this coroutine
Why is this not working?