From caf7ac27916a1afc0cad72f4b6ac21c8404faf70 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 10 Sep 2022 17:11:24 +0200 Subject: async: Add source/sink concepts. --- async/concepts.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 async/concepts.h diff --git a/async/concepts.h b/async/concepts.h new file mode 100644 index 0000000..41f878a --- /dev/null +++ b/async/concepts.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +template +concept async_awaitable = requires(T a) +{ + // TODO: await_ready and await_suspend + { a.await_resume() } -> std::same_as; +}; + +template +concept async_source = requires(T a) +{ + { a.async_get() } -> async_awaitable; +}; + +template +concept async_sink = requires(T a, U v) +{ + { a.async_put(v) } -> async_awaitable<>; +}; + +template +concept async_byte_source = async_source; + +template +concept async_byte_sink = async_sink; + +template +concept async_packet_source = requires(T a, std::span buf) +{ + { a.async_read(buf) } -> async_awaitable>; +}; + +template +concept async_packet_sink = requires(T a, std::span buf) +{ + { a.async_write(buf) } -> async_awaitable<>; +}; -- cgit v1.2.3