我已经尝试std::enable_if
过requires
:
template <typename Ret>
struct promise_type {
auto get_return_object() {/*...*/}
auto initial_suspend() {/*...*/}
auto return_void()
-> std::enable_if_t<std::is_void_v<Ret>> {/*...*/}
auto return_value(Ret)
-> std::enable_if_t<!std::is_void_v<Ret>> {/*...*/}
void unhandled_exception() {/*...*/}
auto final_suspend() noexcept {/*...*/}
// Rest of promise_type's definition ...
};
In file included from src/TestSyncTask.cpp:1:
In file included from include/asyncxx/SyncTask.hpp:2:
In file included from /usr/local/lib/gcc/x86_64-pc-linux-gnu/15.0.1/../../../../include/c++/15.0.1/coroutine:48:
/usr/local/lib/gcc/x86_64-pc-linux-gnu/15.0.1/../../../../include/c++/15.0.1/type_traits:2837:44: error: no type named 'type' in 'std::enable_if<false>'; 'enable_if' cannot be used to disable this declaration
2837 | using enable_if_t = typename enable_if<_Cond, _Tp>::type;
| ^~~~~
include/asyncxx/SyncTask.hpp:12:36: note: in instantiation of template type alias 'enable_if_t' requested here
12 | auto return_void() -> std::enable_if_t<std::is_void_v<Ret>> {}
| ^
src/TestSyncTask.cpp:4:15: note: in instantiation of member class 'SyncTask<int>::promise_type' requested here
4 | SyncTask<int> async_main(const int argc, const char *const argv[]) {
| ^
1 error generated.
template <typename Ret>
struct promise_type {
auto get_return_object() {/*...*/}
auto initial_suspend() {/*...*/}
auto return_void() requires std::is_void_v<Ret> {/*...*/}
auto return_value(Ret) requires (!std::is_void_v<Ret>) {/*...*/}
void unhandled_exception() {/*...*/}
auto final_suspend() noexcept {/*...*/}
// Rest of promise_type's definition ...
};
src/TestSyncTask.cpp:4:15: error: the coroutine promise type 'promise_type' declares both 'return_value' and 'return_void'
4 | SyncTask<int> async_main(const int argc, const char *const argv[]) {
| ^
include/asyncxx/SyncTask.hpp:12:14: note: member 'return_void' first declared here
12 | auto return_void() requires std::is_void_v<Ret> {}
| ^
include/asyncxx/SyncTask.hpp:13:14: note: member 'return_value' first declared here
13 | auto return_value(Ret val) requires (!std::is_void_v<Ret>) {
| ^
1 error generated.
我该如何修复此问题?