Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:50

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_DETAIL_IS_AWAITER_HPP_INCLUDED
0006 #define CPPCORO_DETAIL_IS_AWAITER_HPP_INCLUDED
0007 
0008 #include <type_traits>
0009 #include <cppcoro/coroutine.hpp>
0010 
0011 namespace cppcoro
0012 {
0013     namespace detail
0014     {
0015         template<typename T>
0016         struct is_coroutine_handle
0017             : std::false_type
0018         {};
0019 
0020         template<typename PROMISE>
0021         struct is_coroutine_handle<cppcoro::coroutine_handle<PROMISE>>
0022             : std::true_type
0023         {};
0024 
0025         // NOTE: We're accepting a return value of coroutine_handle<P> here
0026         // which is an extension supported by Clang which is not yet part of
0027         // the C++ coroutines TS.
0028         template<typename T>
0029         struct is_valid_await_suspend_return_value : std::disjunction<
0030             std::is_void<T>,
0031             std::is_same<T, bool>,
0032             is_coroutine_handle<T>>
0033         {};
0034 
0035         template<typename T, typename = std::void_t<>>
0036         struct is_awaiter : std::false_type {};
0037 
0038         // NOTE: We're testing whether await_suspend() will be callable using an
0039         // arbitrary coroutine_handle here by checking if it supports being passed
0040         // a coroutine_handle<void>. This may result in a false-result for some
0041         // types which are only awaitable within a certain context.
0042         template<typename T>
0043         struct is_awaiter<T, std::void_t<
0044             decltype(std::declval<T>().await_ready()),
0045             decltype(std::declval<T>().await_suspend(std::declval<cppcoro::coroutine_handle<>>())),
0046             decltype(std::declval<T>().await_resume())>> :
0047             std::conjunction<
0048                 std::is_constructible<bool, decltype(std::declval<T>().await_ready())>,
0049                 detail::is_valid_await_suspend_return_value<
0050                     decltype(std::declval<T>().await_suspend(std::declval<cppcoro::coroutine_handle<>>()))>>
0051         {};
0052     }
0053 }
0054 
0055 #endif