From 4b872101d27a55ec03f869706bdd0202f83c30bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Date: Tue, 6 Sep 2022 11:35:50 +0200 Subject: [PATCH 1/5] *: rewrite to concepts --- include/async/algorithm.hpp | 5 +- include/async/basic.hpp | 45 ++++--- include/async/execution.hpp | 257 ++++++++++++++++-------------------- 3 files changed, 143 insertions(+), 164 deletions(-) diff --git a/include/async/algorithm.hpp b/include/async/algorithm.hpp index a0631e2..7a280b8 100644 --- a/include/async/algorithm.hpp +++ b/include/async/algorithm.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -141,7 +142,7 @@ template struct [[nodiscard]] transform_sender; template -requires (!std::is_same_v) +requires (!std::same_as) struct [[nodiscard]] transform_sender { using value_type = std::invoke_result_t; @@ -160,7 +161,7 @@ struct [[nodiscard]] transform_sender { }; template -requires std::is_same_v +requires std::same_as struct [[nodiscard]] transform_sender { using value_type = std::invoke_result_t; diff --git a/include/async/basic.hpp b/include/async/basic.hpp index 2caf4b6..c0a4ce5 100644 --- a/include/async/basic.hpp +++ b/include/async/basic.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -156,11 +157,12 @@ struct [[nodiscard]] sender_awaiter { template struct any_receiver { template + requires ( + std::is_trivially_copyable_v + && sizeof(R) <= sizeof(void *) + && alignof(R) <= alignof(void *) + ) any_receiver(R receiver) { - static_assert(std::is_trivially_copyable_v); - static_assert(sizeof(R) <= sizeof(void *)); - static_assert(alignof(R) <= alignof(void *)); - new (stor_) R(receiver); set_value_fptr_ = [] (void *p, T value) { auto *rp = static_cast(p); @@ -184,8 +186,12 @@ struct any_receiver { template<> struct any_receiver { template + requires ( + std::is_trivially_copyable_v + && sizeof(R) <= sizeof(void *) + && alignof(R) <= alignof(void *) + ) any_receiver(R receiver) { - static_assert(std::is_trivially_copyable_v); new (stor_) R(receiver); set_value_fptr_ = [] (void *p) { auto *rp = static_cast(p); @@ -227,10 +233,13 @@ struct callback { callback() : _function(nullptr) { } - template::value - && std::is_trivially_destructible::value>> + template + requires ( + sizeof(F) <= sizeof(void*) + && alignof(F) <= alignof(void*) + && std::is_trivially_copy_constructible_v + && std::is_trivially_destructible_v + ) callback(F functor) : _function(&invoke) { new (&_object) F{std::move(functor)}; @@ -323,8 +332,8 @@ void run_forever(IoService ios) { } template -std::enable_if_t, void> -run(Sender s) { +requires std::same_as +void run(Sender s) { struct receiver { void set_value_inline() { } @@ -339,9 +348,8 @@ run(Sender s) { } template -std::enable_if_t, - typename Sender::value_type> -run(Sender s) { +requires (!std::same_as) +typename Sender::value_type run(Sender s) { struct state { frg::optional value; }; @@ -372,8 +380,8 @@ run(Sender s) { } template -std::enable_if_t, void> -run(Sender s, IoService ios) { +requires std::same_as +void run(Sender s, IoService ios) { struct state { bool done = false; }; @@ -406,9 +414,8 @@ run(Sender s, IoService ios) { } template -std::enable_if_t, - typename Sender::value_type> -run(Sender s, IoService ios) { +requires (!std::same_as) +typename Sender::value_type run(Sender s, IoService ios) { struct state { bool done = false; frg::optional value; diff --git a/include/async/execution.hpp b/include/async/execution.hpp index 25d31a6..528bd3b 100644 --- a/include/async/execution.hpp +++ b/include/async/execution.hpp @@ -2,154 +2,125 @@ #include #include +#include -namespace async { - -// Detection pattern boilerplate. - -template -using void_t = void; - -template -constexpr bool dependent_false_t = false; - -template