Commit e72659cd authored by Xavier Thompson's avatar Xavier Thompson

Add AwaitResult metafunction

parent 76287636
......@@ -21,13 +21,19 @@ namespace typon::meta
};
/* inspired by and simplified from
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1288r0.pdf
*/
template <typename T>
concept Awaitable = Awaiter<std::remove_cvref_t<T>> || requires (T && a)
concept HasCoAwait = requires (T && a)
{
// simplified
std::forward<T>(a).operator co_await();
};
template <typename T>
concept Awaitable = Awaiter<T> || HasCoAwait<T>;
template <typename T>
requires (! Awaitable<T>)
......@@ -46,6 +52,25 @@ namespace typon::meta
}
};
template <typename T>
struct AwaitResult_t {
using type = T;
};
template <typename T>
using AwaitResult = typename AwaitResult_t<T>::type;
template <Awaiter T>
struct AwaitResult_t<T> {
using type = decltype(std::declval<T>().await_resume());
};
template <HasCoAwait T>
struct AwaitResult_t<T> {
using type = AwaitResult<decltype(std::declval<T>().operator co_await())>;
};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment