From b2268790a589065a6a514b0c9bf518ee1ab779f5 Mon Sep 17 00:00:00 2001 From: Sean Parent Date: Wed, 21 Feb 2024 15:26:08 -0800 Subject: [PATCH] Using new tuple code. --- test/initial_draft.cpp | 76 +++++------------------------------------- 1 file changed, 9 insertions(+), 67 deletions(-) diff --git a/test/initial_draft.cpp b/test/initial_draft.cpp index 9d940c3..f239ecf 100644 --- a/test/initial_draft.cpp +++ b/test/initial_draft.cpp @@ -1,6 +1,8 @@ #include +#include + #include #include @@ -18,68 +20,7 @@ set on the receiver. */ -namespace stlab::inline v1 { - -namespace detail { - -/* - Operators for fold expression for sequential execution. Simpler way? -*/ - -template -inline auto void_to_monostate(F& f) { - return [&_f = f](auto&&... args) mutable { - if constexpr (std::is_same_v(args)...)), - void>) { - std::move(_f)(std::forward(args)...); - return std::monostate{}; - } else { - return std::move(_f)(std::forward(args)...); - } - }; -} - -template -struct pipeable; - -template -struct pipeable { - T _value; - pipeable(T&& a) : _value{std::move(a)} {} -}; - -template -auto operator|(pipeable&& p, F& f) { - return pipeable{void_to_monostate(f)(std::move(p._value))}; -} - -/* REVISIT (sparent) : how to forward a value through `just`? */ - -template -struct just_ref { - T& _value; - just_ref(T& a) : _value{a} {} -}; - -template -auto operator|(just_ref&& p, F&& f) { - return pipeable{std::apply(std::forward(f), std::move(p._value))}; -} - -} // namespace detail - -template -auto compose_tuple(std::tuple&& sequence) { - return [_sequence = std::move(sequence)](auto&&... args) mutable { - return std::move(std::apply( - [_args = std::forward_as_tuple(std::forward(args)...)]( - auto&... functions) mutable { - return (detail::just_ref{_args} | ... | functions); - }, - _sequence) - ._value); - }; -} +namespace chain::inline v1 { /* segment is invoked with a receiver - @@ -96,7 +37,7 @@ class segment { public: template auto result_type_helper(Args&&... args) && { - return compose_tuple(std::move(_functions))(std::forward(args)...); + return tuple_compose(std::move(_functions))(std::forward(args)...); } explicit segment(Applicator&& apply, std::tuple&& functions) @@ -139,7 +80,7 @@ class segment { if (receiver.canceled()) return; std::move(_apply)( - [_f = compose_tuple(std::move(_functions)), + [_f = tuple_compose(std::move(_functions)), _receiver = receiver](auto&&... args) mutable noexcept { if (_receiver.canceled()) return; try { @@ -264,14 +205,14 @@ inline auto operator|(segment&& head, F&& f) { return chain{std::tuple<>{}, std::move(head).append(std::forward(f))}; } -} // namespace stlab::inline v1 +} // namespace chain::inline v1 //-------------------------------------------------------------------------------------------------- #include #include -namespace stlab::inline v1 { +namespace chain::inline v1 { #if 0 template @@ -343,7 +284,7 @@ inline auto then(F&& future) { #endif -} // namespace stlab::inline v1 +} // namespace chain::inline v1 //-------------------------------------------------------------------------------------------------- @@ -353,6 +294,7 @@ inline auto then(F&& future) { #include using namespace std; +using namespace chain; using namespace stlab; TEST_CASE("Initial draft", "[initial_draft]") {