From e038452a2bf337f0c06662af28b758574fc972bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Wed, 4 Sep 2024 20:11:47 +0100 Subject: [PATCH 1/5] saving a version of then --- docs/questions.md | 3 +- .../execution26/detail/sender_adaptor.hpp | 2 + include/beman/execution26/detail/then.hpp | 134 ++++++++++++++++++ src/beman/execution26/CMakeLists.txt | 1 + src/beman/execution26/tests/CMakeLists.txt | 1 + .../execution26/tests/exec-then.pass.cpp | 57 ++++++++ 6 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 include/beman/execution26/detail/then.hpp create mode 100644 src/beman/execution26/tests/exec-then.pass.cpp diff --git a/docs/questions.md b/docs/questions.md index 1791f952..601b0463 100644 --- a/docs/questions.md +++ b/docs/questions.md @@ -42,4 +42,5 @@ likely observable. - [exec.sync_wait] are sync_wait(just_error(17)) and sync_wait(just_stopped()) supposed to work? I don't see a reason why a value completion is necessarily required. As is, they are not because type_idenity_t ends up being used without - argument. \ No newline at end of file + argument. +- [exec.then] p5 seems to miss a space betweend sendr and out_sndr \ No newline at end of file diff --git a/include/beman/execution26/detail/sender_adaptor.hpp b/include/beman/execution26/detail/sender_adaptor.hpp index a84e9ad5..8e05f80b 100644 --- a/include/beman/execution26/detail/sender_adaptor.hpp +++ b/include/beman/execution26/detail/sender_adaptor.hpp @@ -42,6 +42,8 @@ namespace beman::execution26::detail return apply(::std::forward(sender), *this); } }; + template + sender_adaptor(T&&...) -> sender_adaptor; } // ---------------------------------------------------------------------------- diff --git a/include/beman/execution26/detail/then.hpp b/include/beman/execution26/detail/then.hpp new file mode 100644 index 00000000..d326ef00 --- /dev/null +++ b/include/beman/execution26/detail/then.hpp @@ -0,0 +1,134 @@ +// include/beman/execution26/detail/then.hpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_THEN +#define INCLUDED_BEMAN_EXECUTION26_DETAIL_THEN + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace beman::execution26::detail +{ + template + struct then_t + : ::beman::execution26::sender_adaptor_closure> + { + template <::beman::execution26::detail::movable_value Fun> + auto operator()(Fun&& fun) const + { + return ::beman::execution26::detail::sender_adaptor{ + *this, ::std::forward(fun) + }; + } + template <::beman::execution26::sender Sender, + ::beman::execution26::detail::movable_value Fun> + auto operator()(Sender&& sender, Fun&& fun) const + { + auto domain{::beman::execution26::detail::get_domain_early(sender)}; + return ::beman::execution26::transform_sender( + domain, + ::beman::execution26::detail::make_sender( + *this, + ::std::forward(fun), + ::std::forward(sender) + ) + ); + } + }; + + template + struct impls_for> + : ::beman::execution26::detail::default_impls + { + static constexpr auto complete + = [] + (auto, auto& fun, auto& receiver, Tag, Args&&... args) + noexcept + -> void + { + if constexpr (::std::same_as) + { + try + { + auto invoke = [&]{ + return ::std::invoke(::std::move(fun), + ::std::forward(args)...); + }; + if constexpr (::std::same_as) + { + invoke(); + ::beman::execution26::set_value( + ::std::move(receiver) + ); + } + else + { + ::beman::execution26::set_value( + ::std::move(receiver), + invoke() + ); + } + } + catch (...) + { + ::beman::execution26::set_error( + ::std::move(receiver), + ::std::current_exception() + ); + } + } + else + { + Tag()(::std::move(receiver), ::std::forward(args)...); + } + }; + }; + + + template + struct completion_signatures_for_impl< + ::beman::execution26::detail::basic_sender< + ::beman::execution26::detail::then_t<::beman::execution26::set_stopped_t>, + Fun, + Sender + >, + Env + > + { + using type = ::beman::execution26::completion_signatures< + >; + }; +} + +namespace beman::execution26 +{ + using then_t = ::beman::execution26::detail::then_t<::beman::execution26::set_value_t>; + using upon_error_t = ::beman::execution26::detail::then_t<::beman::execution26::set_error_t>; + using upon_stopped_t = ::beman::execution26::detail::then_t<::beman::execution26::set_stopped_t>; + + inline constexpr ::beman::execution26::then_t then{}; + inline constexpr ::beman::execution26::upon_error_t upon_error{}; + inline constexpr ::beman::execution26::upon_stopped_t upon_stopped{}; +} + +// ---------------------------------------------------------------------------- + +#endif diff --git a/src/beman/execution26/CMakeLists.txt b/src/beman/execution26/CMakeLists.txt index f34f21b6..5556a768 100644 --- a/src/beman/execution26/CMakeLists.txt +++ b/src/beman/execution26/CMakeLists.txt @@ -123,6 +123,7 @@ target_sources(${TARGET_LIBRARY} ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/stoppable_token.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/sync_wait.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/tag_of_t.hpp + ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/then.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/transform_sender.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/type_list.hpp ${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/unstoppable_token.hpp diff --git a/src/beman/execution26/tests/CMakeLists.txt b/src/beman/execution26/tests/CMakeLists.txt index b422c4f0..ff541961 100644 --- a/src/beman/execution26/tests/CMakeLists.txt +++ b/src/beman/execution26/tests/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception list(APPEND execution_tests + exec-then.pass exec-read-env.pass exec-get-delegation-scheduler.pass exec-snd-apply.pass diff --git a/src/beman/execution26/tests/exec-then.pass.cpp b/src/beman/execution26/tests/exec-then.pass.cpp new file mode 100644 index 00000000..18688a18 --- /dev/null +++ b/src/beman/execution26/tests/exec-then.pass.cpp @@ -0,0 +1,57 @@ +// src/beman/execution26/tests/exec-then.pass.cpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +namespace +{ + struct error { int value{}; }; + struct non_sender {}; + + struct receiver + { + using receiver_concept = test_std::receiver_t; + + auto set_error(auto&&) && noexcept -> void {} + auto set_stopped() && noexcept -> void {} + auto set_value(auto&&...) && noexcept -> void {} + }; + + template + auto test_has(auto cpo, auto in_sender, auto fun) -> void + { + static_assert(test_std::receiver); + static_assert(Expect == requires{ { cpo(in_sender, fun) } -> test_std::sender; }); + if constexpr (Expect) + { + static_assert(requires{ cpo(fun); }); + static_assert(requires{ in_sender | cpo(fun); }); + static_assert(requires{ { in_sender | cpo(fun) } -> test_std::sender; }); + static_assert(requires{ { in_sender | cpo(fun) | cpo([](auto&&...){}) } -> test_std::sender; }); + auto sender{cpo(in_sender, fun)}; + test::use(sender); + auto op{test_std::connect(sender, receiver{})}; + test::use(op); + test_std::start(op); + } + } +} + +auto main() -> int +{ + static_assert(std::same_as); + static_assert(std::same_as); + static_assert(std::same_as); + + test_has(test_std::then, non_sender{}, []{}); + test_has(test_std::then, test_std::just(), []{}); + test_has(test_std::then, test_std::just_error(error{3}), []{}); + test_has(test_std::then, test_std::just_stopped(), []{}); +} \ No newline at end of file From 86559bf3c80375cdebe39529716a28164668f7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Wed, 4 Sep 2024 20:32:47 +0100 Subject: [PATCH 2/5] made meta::unique stable --- .../beman/execution26/detail/meta_unique.hpp | 32 +++++++++++++++++++ .../execution26/tests/meta-unique.pass.cpp | 4 +-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/beman/execution26/detail/meta_unique.hpp b/include/beman/execution26/detail/meta_unique.hpp index 9b234a8d..0d589167 100644 --- a/include/beman/execution26/detail/meta_unique.hpp +++ b/include/beman/execution26/detail/meta_unique.hpp @@ -13,8 +13,11 @@ namespace beman::execution26::detail::meta::detail { + template struct make_unique; template struct unique; +#if 0 + template