diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-09-10 17:11:24 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-09-10 17:11:24 +0200 |
commit | caf7ac27916a1afc0cad72f4b6ac21c8404faf70 (patch) | |
tree | 495709f6afffe5d80f0eeb8715f726c1c5bdc73b | |
parent | 7154aa76c18e89db23092e04b15fb21dc1d54103 (diff) |
async: Add source/sink concepts.
-rw-r--r-- | async/concepts.h | 42 |
1 files changed, 42 insertions, 0 deletions
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 <concepts> +#include <cstdint> +#include <span> + +template <typename T, typename U = void> +concept async_awaitable = requires(T a) +{ + // TODO: await_ready and await_suspend + { a.await_resume() } -> std::same_as<U>; +}; + +template <typename T, typename U> +concept async_source = requires(T a) +{ + { a.async_get() } -> async_awaitable<U>; +}; + +template <typename T, typename U> +concept async_sink = requires(T a, U v) +{ + { a.async_put(v) } -> async_awaitable<>; +}; + +template <typename T> +concept async_byte_source = async_source<T, uint8_t>; + +template <typename T> +concept async_byte_sink = async_sink<T, uint8_t>; + +template <typename T> +concept async_packet_source = requires(T a, std::span<uint8_t> buf) +{ + { a.async_read(buf) } -> async_awaitable<std::span<uint8_t>>; +}; + +template <typename T> +concept async_packet_sink = requires(T a, std::span<uint8_t> buf) +{ + { a.async_write(buf) } -> async_awaitable<>; +}; |