Skip to content

Commit

Permalink
使用 is_awaiter_v , 兼容下 test3
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Oct 2, 2024
1 parent 884b0a1 commit 8642d61
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions include/ucoro/awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,25 @@ namespace ucoro
: std::true_type
{};

// NOTE: We're accepting a return value of coroutine_handle<P> here
// which is an extension supported by Clang which is not yet part of
// the C++ coroutines TS.
template<typename T>
struct is_valid_await_suspend_return_value : std::disjunction<
std::is_void<T>,
std::is_same<T, bool>,
is_coroutine_handle<T>>
{};

// NOTE: We're testing whether await_suspend() will be callable using an
// arbitrary coroutine_handle here by checking if it supports being passed
// a coroutine_handle<void>. This may result in a false-result for some
// types which are only awaitable within a certain context.
template <typename T>
concept is_awaiter = requires ( T a)
concept is_awaiter_v = requires ( T a)
{
{ a.await_ready() } -> std::convertible_to<bool>;
{ a.await_suspend(std::declval<std::coroutine_handle<>>()) }; //-> std::convertible_to<std::coroutine_handle<>>;
{ a.await_suspend(std::declval<std::coroutine_handle<>>()) };// -> ( std::convertible_to<std::coroutine_handle<>> | std::convertible_to<bool> );
{ a.await_resume() };
};
} // namespace detail
Expand Down Expand Up @@ -149,7 +159,7 @@ namespace ucoro

void unhandled_exception() {}

template <typename A> requires( detail::is_awaiter<A> )
template <typename A> requires( detail::is_awaiter_v<A> )
auto await_transform(A awaiter) const
{
return awaiter;
Expand Down

0 comments on commit 8642d61

Please sign in to comment.