Skip to content

Commit

Permalink
added on algorithm and applies various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dietmarkuehl committed Jan 4, 2025
1 parent 2560003 commit 00cce59
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 44 deletions.
6 changes: 3 additions & 3 deletions include/beman/execution26/detail/basic_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ struct basic_sender : ::beman::execution26::detail::product_type<Tag, Data, Chil
return {::std::forward<Self>(self), ::std::move(receiver)};
}
#endif
#if __cpp_explicit_this_parameter < 202110L
#if __cpp_explicit_this_parameter < 302110L
template <typename Env>
auto
get_completion_signatures(Env&&) && -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
return {};
}
template <typename Env>
auto get_completion_signatures(
Env&&) const&& -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
Env&&) const&& -> ::beman::execution26::detail::completion_signatures_for<const basic_sender, Env> {
return {};
}
template <typename Env>
Expand All @@ -92,7 +92,7 @@ struct basic_sender : ::beman::execution26::detail::product_type<Tag, Data, Chil
}
template <typename Env>
auto get_completion_signatures(
Env&&) const& -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
Env&&) const& -> ::beman::execution26::detail::completion_signatures_for<const basic_sender, Env> {
return {};
}
#else
Expand Down
4 changes: 3 additions & 1 deletion include/beman/execution26/detail/connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace beman::execution26::detail {
struct connect_t {
private:
template <typename Sender, typename Receiver>
static auto make_new_sender(Sender&& sender, Receiver&& receiver) noexcept(true) -> decltype(auto) {
static auto make_new_sender(Sender&& sender, Receiver&& receiver)
//-dk:TODO this noexcept needs to get confirmed/fixed
noexcept(true) -> decltype(auto) {
return ::beman::execution26::transform_sender(
decltype(::beman::execution26::detail::get_domain_late(::std::forward<Sender>(sender),
::beman::execution26::get_env(receiver))){},
Expand Down
84 changes: 82 additions & 2 deletions include/beman/execution26/detail/on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
#include <beman/execution26/detail/forward_like.hpp>
#include <beman/execution26/detail/fwd_env.hpp>
#include <beman/execution26/detail/sched_env.hpp>
#include <beman/execution26/detail/starts_on.hpp>
#include <beman/execution26/detail/continues_on.hpp>
#include <beman/execution26/detail/write_env.hpp>
#include <utility>

// ----------------------------------------------------------------------------

namespace beman::execution26::detail {
struct on_t {
struct on_t : ::beman::execution26::sender_adaptor_closure<on_t> {
template <::beman::execution26::detail::sender_for<on_t> OutSndr, typename Env>
auto transform_env(OutSndr&& out_sndr, Env&& env) const -> decltype(auto) {
// auto&&[_, data, _] = out_sndr;
auto&& data{out_sndr.template get<1>()};

if constexpr (::beman::execution26::scheduler<decltype(data)>)
Expand All @@ -40,6 +42,56 @@ struct on_t {
return std::forward<Env>(env);
}

template <typename>
struct env_needs_get_scheduler {
using sender_concept = ::beman::execution26::sender_t;
template <typename Env>
auto get_completion_signatures(Env&&) const {
return env_needs_get_scheduler<Env>{};
}
};

template <::beman::execution26::detail::sender_for<on_t> OutSndr, typename Env>
auto transform_sender(OutSndr&& out_sndr, Env&& env) const -> decltype(auto) {
struct not_a_scheduler {};
auto&& [_, data, child] = out_sndr;

if constexpr (::beman::execution26::scheduler<decltype(data)>) {
auto sch{::beman::execution26::detail::query_with_default(
::beman::execution26::get_scheduler, env, not_a_scheduler{})};
if constexpr (::std::same_as<not_a_scheduler, decltype(sch)>) {
return env_needs_get_scheduler<Env>{};
} else {
return ::beman::execution26::continues_on(
::beman::execution26::starts_on(::beman::execution26::detail::forward_like<OutSndr>(data),
::beman::execution26::detail::forward_like<OutSndr>(child)),
::std::move(sch));
}
} else {
auto& [sch, closure] = data;
auto orig_sch{::beman::execution26::detail::query_with_default(
::beman::execution26::get_completion_scheduler<::beman::execution26::set_value_t>,
::beman::execution26::get_env(child),
::beman::execution26::detail::query_with_default(
::beman::execution26::get_scheduler, env, not_a_scheduler{}))};

if constexpr (::std::same_as<not_a_scheduler, decltype(orig_sch)>) {
return env_needs_get_scheduler<Env>{};
} else {
return ::beman::execution26::detail::write_env(
::beman::execution26::continues_on(
::beman::execution26::detail::forward_like<OutSndr>(closure)(
::beman::execution26::continues_on(
::beman::execution26::detail::write_env(
::beman::execution26::detail::forward_like<OutSndr>(child),
::beman::execution26::detail::sched_env(orig_sch)),
sch)),
orig_sch),
::beman::execution26::detail::sched_env(env));
}
}
}

template <::beman::execution26::scheduler Sch, ::beman::execution26::sender Sndr>
requires ::beman::execution26::detail::is_sender_adaptor_closure<Sndr>
auto operator()(Sch&&, Sndr&&) const -> void =
Expand Down Expand Up @@ -72,7 +124,35 @@ struct on_t {
::beman::execution26::detail::product_type{::std::forward<Sch>(sch), ::std::forward<Closure>(closure)},
::std::forward<Sndr>(sndr)));
}
template <::beman::execution26::scheduler Sch, ::beman::execution26::detail::is_sender_adaptor_closure Closure>
auto operator()(Sch&& sch, Closure&& closure) const {
return ::beman::execution26::detail::sender_adaptor{
*this, ::std::forward<Sch>(sch), ::std::forward<Closure>(closure)};
}
};

#if 0
template <typename Data, typename Sender, typename Env>
struct completion_signatures_for_impl<
::beman::execution26::detail::basic_sender<::beman::execution26::detail::on_t, Data, Sender>,
Env> {
//-dk:TODO pick up scheduler errors and merge them in?
using type =
#if 0
::beman::execution26::detail::meta::combine<
::beman::execution26::completion_signatures_of_t<Sender, Env>,
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(::std::exception_ptr)>
>
#else
::beman::execution26::completion_signatures<
::beman::execution26::set_value_t(),
::beman::execution26::set_error_t(::std::exception_ptr)
>
#endif
;
};
#endif

} // namespace beman::execution26::detail

namespace beman::execution26 {
Expand Down
15 changes: 6 additions & 9 deletions include/beman/execution26/detail/product_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template <::std::size_t... I, typename... T>
struct product_type_base<::std::index_sequence<I...>, T...>
: ::beman::execution26::detail::product_type_element<I, T>... {
static constexpr ::std::size_t size() { return sizeof...(T); }
static constexpr bool is_product_type{true};
static constexpr bool is_product_type{true};

template <::std::size_t J, typename S>
static auto element_get(::beman::execution26::detail::product_type_element<J, S>& self) noexcept -> S& {
Expand Down Expand Up @@ -67,8 +67,7 @@ struct product_type_base<::std::index_sequence<I...>, T...>
};

template <typename T>
concept is_product_type_c = requires(T const& t){ T::is_product_type; };

concept is_product_type_c = requires(const T& t) { T::is_product_type; };

template <typename... T>
struct product_type : ::beman::execution26::detail::product_type_base<::std::index_sequence_for<T...>, T...> {
Expand Down Expand Up @@ -115,15 +114,13 @@ constexpr auto is_product_type(const ::beman::execution26::detail::product_type<

namespace std {
template <typename T>
requires ::beman::execution26::detail::is_product_type_c<T>
struct tuple_size<T>
: ::std::integral_constant<std::size_t, T::size()> {};
requires ::beman::execution26::detail::is_product_type_c<T>
struct tuple_size<T> : ::std::integral_constant<std::size_t, T::size()> {};

template <::std::size_t I, typename T>
requires ::beman::execution26::detail::is_product_type_c<T>
requires ::beman::execution26::detail::is_product_type_c<T>
struct tuple_element<I, T> {
using type =
::std::decay_t<decltype(::std::declval<T>().template get<I>())>;
using type = ::std::decay_t<decltype(::std::declval<T>().template get<I>())>;
};
} // namespace std

Expand Down
26 changes: 20 additions & 6 deletions include/beman/execution26/detail/schedule_from.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHEDULE_FROM

#include <beman/execution26/detail/child_type.hpp>
#include <beman/execution26/detail/meta_combine.hpp>
#include <beman/execution26/detail/completion_signatures_of_t.hpp>
#include <beman/execution26/detail/connect.hpp>
#include <beman/execution26/detail/decayed_tuple.hpp>
#include <beman/execution26/detail/default_domain.hpp>
#include <beman/execution26/detail/default_impls.hpp>
#include <beman/execution26/detail/error_types_of_t.hpp>
#include <beman/execution26/detail/env_of_t.hpp>
#include <beman/execution26/detail/fwd_env.hpp>
#include <beman/execution26/detail/get_domain.hpp>
Expand Down Expand Up @@ -144,10 +146,15 @@ struct impls_for<::beman::execution26::detail::schedule_from_t> : ::beman::execu
::std::monostate,
::beman::execution26::detail::meta::transform<
::beman::execution26::detail::as_tuple_t,
::beman::execution26::detail::meta::to<::std::variant,
::beman::execution26::completion_signatures_of_t<
::beman::execution26::detail::child_type<Sender>,
::beman::execution26::env_of_t<Receiver>>>>>>;
::beman::execution26::detail::meta::to<
::std::variant,
::beman::execution26::detail::meta::combine<
::beman::execution26::completion_signatures_of_t<
::beman::execution26::detail::child_type<Sender>,
::beman::execution26::env_of_t<Receiver>>,
//-dk:TODO get proper error completion signatures
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(
::std::exception_ptr)>>>>>>;

return state_type<Receiver, sched_t, variant_t>(sch, receiver);
}};
Expand Down Expand Up @@ -176,8 +183,15 @@ template <typename Scheduler, typename Sender, typename Env>
struct completion_signatures_for_impl<
::beman::execution26::detail::basic_sender<::beman::execution26::detail::schedule_from_t, Scheduler, Sender>,
Env> {
using type =
decltype(::beman::execution26::get_completion_signatures(::std::declval<Sender>(), ::std::declval<Env>()));
using scheduler_sender = decltype(::beman::execution26::schedule(::std::declval<Scheduler>()));
template <typename... E>
using as_set_error = ::beman::execution26::completion_signatures<::beman::execution26::set_error_t(E)...>;
using type = ::beman::execution26::detail::meta::combine<
decltype(::beman::execution26::get_completion_signatures(::std::declval<Sender>(), ::std::declval<Env>())),
::beman::execution26::error_types_of_t<scheduler_sender, Env, as_set_error>,
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(
::std::exception_ptr)> //-dk:TODO this one should be deduced
>;
};
} // namespace beman::execution26::detail

Expand Down
25 changes: 12 additions & 13 deletions include/beman/execution26/detail/transform_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
requires(Domain dom, Sender&& sender, const Env&... env) {
dom.transform_sender(::std::forward<Sender>(sender), env...);
} &&
(::std::same_as<
::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
(::std::same_as<::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
constexpr auto transform_sender(Domain, Sender&& sender, const Env&...) noexcept -> ::beman::execution26::sender auto {
return ::std::forward<Sender>(sender);
}
Expand All @@ -28,9 +28,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
requires(Domain dom, Sender&& sender, const Env&... env) {
dom.transform_sender(::std::forward<Sender>(sender), env...);
} &&
(not::std::same_as<
::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
(not::std::same_as<::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept
-> ::beman::execution26::sender decltype(auto) {
return ::beman::execution26::detail::transform_sender(
Expand Down Expand Up @@ -60,7 +60,6 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept(noexcept(
::beman::execution26::default_domain{}.transform_sender(::std::declval<Sender>(), ::std::declval<Env>()...)))
-> ::beman::execution26::sender decltype(auto) {
(void)dom;
return ::beman::execution26::detail::transform_sender(
dom, ::beman::execution26::default_domain{}.transform_sender(::std::forward<Sender>(sender), env...), env...);
}
Expand All @@ -72,9 +71,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
requires(Domain dom, Sender&& sender, const Env&... env) {
dom.transform_sender(::std::forward<Sender>(sender), env...);
} &&
(::std::same_as<
::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
(::std::same_as<::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
constexpr auto transform_sender(Domain, Sender&& sender, const Env&...) noexcept -> ::beman::execution26::sender
decltype(auto) {
return ::std::forward<Sender>(sender);
Expand All @@ -85,9 +84,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
requires(Domain dom, Sender&& sender, const Env&... env) {
dom.transform_sender(::std::forward<Sender>(sender), env...);
} &&
(not::std::same_as<
::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
(not::std::same_as<::std::remove_cvref_t<Sender>,
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept
-> ::beman::execution26::sender auto {
return ::beman::execution26::detail::transform_sender(
Expand Down
2 changes: 1 addition & 1 deletion include/beman/execution26/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <beman/execution26/detail/into_variant.hpp>
#include <beman/execution26/detail/just.hpp>
#include <beman/execution26/detail/let.hpp>
// #include <beman/execution26/detail/on.hpp>
#include <beman/execution26/detail/on.hpp>
#include <beman/execution26/detail/read_env.hpp>
#include <beman/execution26/detail/schedule_from.hpp>
#include <beman/execution26/detail/starts_on.hpp>
Expand Down
Loading

0 comments on commit 00cce59

Please sign in to comment.