Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed then exceptions #23

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions include/beman/execution26/detail/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <beman/execution26/detail/impls_for.hpp>
#include <beman/execution26/detail/make_sender.hpp>
#include <beman/execution26/detail/meta_transform.hpp>
#include <beman/execution26/detail/meta_combine.hpp>
#include <beman/execution26/detail/meta_unique.hpp>
#include <beman/execution26/detail/movable_value.hpp>
#include <beman/execution26/detail/sender.hpp>
Expand Down Expand Up @@ -93,10 +94,17 @@ namespace beman::execution26::detail
}
catch (...)
{
::beman::execution26::set_error(
::std::move(receiver),
::std::current_exception()
);
if constexpr (not noexcept(
::std::invoke(::std::move(fun),
::std::forward<Args>(args)...)

))
{
::beman::execution26::set_error(
::std::move(receiver),
::std::current_exception()
);
}
}
}
else
Expand All @@ -123,6 +131,16 @@ namespace beman::execution26::detail
using type = Completion;
};

template <typename Fun, typename Completion, typename... T>
struct then_transform<Fun, Completion, Completion(T...)>
{
using type =
typename ::beman::execution26::detail::then_set_value<
::beman::execution26::detail::call_result_t<Fun, T...>
>::type
;
};

template <typename Fun, typename Replace>
struct then_transform_t
{
Expand All @@ -132,12 +150,23 @@ namespace beman::execution26::detail
::type;
};

template <typename Fun, typename Completion, typename... T>
struct then_transform<Fun, Completion, Completion(T...)>
template <typename, typename, typename>
struct then_exception_fun: ::std::false_type {};
template <typename Comp, typename Fun, typename... A>
struct then_exception_fun<Comp, Fun, Comp(A...)>
: ::std::bool_constant<not noexcept(::std::declval<Fun>()(::std::declval<A>()...))>
{
using type = typename ::beman::execution26::detail::then_set_value<
::beman::execution26::detail::call_result_t<Fun, T...>
>::type;
};

template <typename, typename, typename>
struct then_exception: ::std::false_type {};
template <typename Comp, typename Fun, typename Completion, typename... Completions>
struct then_exception<Comp, Fun, ::beman::execution26::completion_signatures<Completion, Completions...>>
{
static constexpr bool value{
then_exception_fun<Comp, Fun, Completion>::value
|| then_exception<Comp, Fun, ::beman::execution26::completion_signatures<Completions...>>::value
};
};

template <typename Completion, typename Fun, typename Sender, typename Env>
Expand All @@ -151,9 +180,20 @@ namespace beman::execution26::detail
>
{
using type = ::beman::execution26::detail::meta::unique<
::beman::execution26::detail::meta::transform<
::beman::execution26::detail::then_transform_t<Fun, Completion>::template transform,
::beman::execution26::completion_signatures_of_t<Sender, Env>
::beman::execution26::detail::meta::combine<
::beman::execution26::detail::meta::transform<
::beman::execution26::detail::then_transform_t<Fun, Completion>::template transform,
::beman::execution26::completion_signatures_of_t<Sender, Env>
>,
::std::conditional_t<
::beman::execution26::detail::then_exception<
Completion,
Fun,
::beman::execution26::completion_signatures_of_t<Sender, Env>
>::value,
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(::std::exception_ptr)>,
::beman::execution26::completion_signatures<>
>
>
>;
};
Expand Down
42 changes: 28 additions & 14 deletions src/beman/execution26/tests/exec-then.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ namespace

auto test_then_type() -> void
{
test_then_type< test_std::set_value_t()>(test_std::just(0) | test_std::then([](auto){}));
test_then_type< test_std::set_value_t(int)>(test_std::just() | test_std::then([]{ return 0; }));
test_then_type< test_std::set_error_t(int)>(test_std::just_error(0) | test_std::then([]{ return 0; }));
test_then_type< test_std::set_stopped_t()>(test_std::just_stopped() | test_std::then([]{ return 0; }));
test_then_type< test_std::set_value_t()>(test_std::just(0) | test_std::then([](auto)noexcept{}));
test_then_type< test_std::set_value_t(int)>(test_std::just() | test_std::then([]()noexcept{ return 0; }));
test_then_type< test_std::set_error_t(int)>(test_std::just_error(0) | test_std::then([]()noexcept{ return 0; }));
test_then_type< test_std::set_stopped_t()>(test_std::just_stopped() | test_std::then([]()noexcept{ return 0; }));

test_then_type< test_std::set_value_t()>(test_std::just() | test_std::upon_error([]{ return 0; }));
test_then_type< test_std::set_value_t()>(test_std::just() | test_std::upon_error([]()noexcept{ return 0; }));
test_then_type< test_std::set_value_t(int)>(test_std::just_error(error{})
| test_std::upon_error([](error){ return 0; }));
test_then_type< test_std::set_stopped_t()>(test_std::just_stopped() | test_std::upon_error([]{}));
| test_std::upon_error([](error)noexcept{ return 0; }));
test_then_type< test_std::set_stopped_t()>(test_std::just_stopped() | test_std::upon_error([]()noexcept{}));

test_then_type< test_std::set_value_t(int)>(test_std::just(0) | test_std::upon_stopped([]{}));
test_then_type< test_std::set_error_t(int)>(test_std::just_error(0) | test_std::upon_stopped([]{}));
test_then_type< test_std::set_value_t()>(test_std::just_stopped() | test_std::upon_stopped([]{}));
test_then_type< test_std::set_value_t(int)>(test_std::just(0) | test_std::upon_stopped([]()noexcept{}));
test_then_type< test_std::set_error_t(int)>(test_std::just_error(0) | test_std::upon_stopped([]()noexcept{}));
test_then_type< test_std::set_value_t()>(test_std::just_stopped() | test_std::upon_stopped([]()noexcept{}));
}

auto test_then_multi_type() -> void
Expand All @@ -102,7 +102,8 @@ namespace
test_then_type<
test_std::set_value_t(bool),
test_std::set_error_t(error),
test_std::set_stopped_t()
test_std::set_stopped_t(),
test_std::set_error_t(::std::exception_ptr)
>(sender<
test_std::set_value_t(),
test_std::set_value_t(int, int),
Expand All @@ -113,7 +114,8 @@ namespace
test_std::set_value_t(),
test_std::set_value_t(int, int),
test_std::set_value_t(bool),
test_std::set_stopped_t()
test_std::set_stopped_t(),
test_std::set_error_t(::std::exception_ptr)
>(sender<
test_std::set_value_t(),
test_std::set_value_t(int, int),
Expand All @@ -123,7 +125,8 @@ namespace
test_then_type<
test_std::set_value_t(),
test_std::set_value_t(int, int),
test_std::set_stopped_t()
test_std::set_stopped_t(),
test_std::set_error_t(::std::exception_ptr)
>(sender<
test_std::set_value_t(),
test_std::set_value_t(int, int),
Expand All @@ -140,7 +143,7 @@ namespace
test_std::set_value_t(int, int),
test_std::set_error_t(error),
test_std::set_stopped_t()
>() | test_std::upon_stopped([]{}));
>() | test_std::upon_stopped([]()noexcept{}));
test_then_type<
test_std::set_value_t(),
test_std::set_value_t(int, int),
Expand All @@ -150,6 +153,17 @@ namespace
test_std::set_value_t(int, int),
test_std::set_error_t(error),
test_std::set_stopped_t()
>() | test_std::upon_stopped([]()noexcept{}));
test_then_type<
test_std::set_value_t(),
test_std::set_value_t(int, int),
test_std::set_error_t(error),
test_std::set_error_t(::std::exception_ptr)
>(sender<
test_std::set_value_t(),
test_std::set_value_t(int, int),
test_std::set_error_t(error),
test_std::set_stopped_t()
>() | test_std::upon_stopped([]{}));
}

Expand Down