Skip to content

Commit 00cce59

Browse files
committed
added on algorithm and applies various fixes
1 parent 2560003 commit 00cce59

File tree

10 files changed

+219
-44
lines changed

10 files changed

+219
-44
lines changed

include/beman/execution26/detail/basic_sender.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ struct basic_sender : ::beman::execution26::detail::product_type<Tag, Data, Chil
7474
return {::std::forward<Self>(self), ::std::move(receiver)};
7575
}
7676
#endif
77-
#if __cpp_explicit_this_parameter < 202110L
77+
#if __cpp_explicit_this_parameter < 302110L
7878
template <typename Env>
7979
auto
8080
get_completion_signatures(Env&&) && -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
8181
return {};
8282
}
8383
template <typename Env>
8484
auto get_completion_signatures(
85-
Env&&) const&& -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
85+
Env&&) const&& -> ::beman::execution26::detail::completion_signatures_for<const basic_sender, Env> {
8686
return {};
8787
}
8888
template <typename Env>
@@ -92,7 +92,7 @@ struct basic_sender : ::beman::execution26::detail::product_type<Tag, Data, Chil
9292
}
9393
template <typename Env>
9494
auto get_completion_signatures(
95-
Env&&) const& -> ::beman::execution26::detail::completion_signatures_for<basic_sender, Env> {
95+
Env&&) const& -> ::beman::execution26::detail::completion_signatures_for<const basic_sender, Env> {
9696
return {};
9797
}
9898
#else

include/beman/execution26/detail/connect.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ namespace beman::execution26::detail {
2323
struct connect_t {
2424
private:
2525
template <typename Sender, typename Receiver>
26-
static auto make_new_sender(Sender&& sender, Receiver&& receiver) noexcept(true) -> decltype(auto) {
26+
static auto make_new_sender(Sender&& sender, Receiver&& receiver)
27+
//-dk:TODO this noexcept needs to get confirmed/fixed
28+
noexcept(true) -> decltype(auto) {
2729
return ::beman::execution26::transform_sender(
2830
decltype(::beman::execution26::detail::get_domain_late(::std::forward<Sender>(sender),
2931
::beman::execution26::get_env(receiver))){},

include/beman/execution26/detail/on.hpp

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919
#include <beman/execution26/detail/forward_like.hpp>
2020
#include <beman/execution26/detail/fwd_env.hpp>
2121
#include <beman/execution26/detail/sched_env.hpp>
22+
#include <beman/execution26/detail/starts_on.hpp>
23+
#include <beman/execution26/detail/continues_on.hpp>
24+
#include <beman/execution26/detail/write_env.hpp>
2225
#include <utility>
2326

2427
// ----------------------------------------------------------------------------
2528

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

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

45+
template <typename>
46+
struct env_needs_get_scheduler {
47+
using sender_concept = ::beman::execution26::sender_t;
48+
template <typename Env>
49+
auto get_completion_signatures(Env&&) const {
50+
return env_needs_get_scheduler<Env>{};
51+
}
52+
};
53+
54+
template <::beman::execution26::detail::sender_for<on_t> OutSndr, typename Env>
55+
auto transform_sender(OutSndr&& out_sndr, Env&& env) const -> decltype(auto) {
56+
struct not_a_scheduler {};
57+
auto&& [_, data, child] = out_sndr;
58+
59+
if constexpr (::beman::execution26::scheduler<decltype(data)>) {
60+
auto sch{::beman::execution26::detail::query_with_default(
61+
::beman::execution26::get_scheduler, env, not_a_scheduler{})};
62+
if constexpr (::std::same_as<not_a_scheduler, decltype(sch)>) {
63+
return env_needs_get_scheduler<Env>{};
64+
} else {
65+
return ::beman::execution26::continues_on(
66+
::beman::execution26::starts_on(::beman::execution26::detail::forward_like<OutSndr>(data),
67+
::beman::execution26::detail::forward_like<OutSndr>(child)),
68+
::std::move(sch));
69+
}
70+
} else {
71+
auto& [sch, closure] = data;
72+
auto orig_sch{::beman::execution26::detail::query_with_default(
73+
::beman::execution26::get_completion_scheduler<::beman::execution26::set_value_t>,
74+
::beman::execution26::get_env(child),
75+
::beman::execution26::detail::query_with_default(
76+
::beman::execution26::get_scheduler, env, not_a_scheduler{}))};
77+
78+
if constexpr (::std::same_as<not_a_scheduler, decltype(orig_sch)>) {
79+
return env_needs_get_scheduler<Env>{};
80+
} else {
81+
return ::beman::execution26::detail::write_env(
82+
::beman::execution26::continues_on(
83+
::beman::execution26::detail::forward_like<OutSndr>(closure)(
84+
::beman::execution26::continues_on(
85+
::beman::execution26::detail::write_env(
86+
::beman::execution26::detail::forward_like<OutSndr>(child),
87+
::beman::execution26::detail::sched_env(orig_sch)),
88+
sch)),
89+
orig_sch),
90+
::beman::execution26::detail::sched_env(env));
91+
}
92+
}
93+
}
94+
4395
template <::beman::execution26::scheduler Sch, ::beman::execution26::sender Sndr>
4496
requires ::beman::execution26::detail::is_sender_adaptor_closure<Sndr>
4597
auto operator()(Sch&&, Sndr&&) const -> void =
@@ -72,7 +124,35 @@ struct on_t {
72124
::beman::execution26::detail::product_type{::std::forward<Sch>(sch), ::std::forward<Closure>(closure)},
73125
::std::forward<Sndr>(sndr)));
74126
}
127+
template <::beman::execution26::scheduler Sch, ::beman::execution26::detail::is_sender_adaptor_closure Closure>
128+
auto operator()(Sch&& sch, Closure&& closure) const {
129+
return ::beman::execution26::detail::sender_adaptor{
130+
*this, ::std::forward<Sch>(sch), ::std::forward<Closure>(closure)};
131+
}
132+
};
133+
134+
#if 0
135+
template <typename Data, typename Sender, typename Env>
136+
struct completion_signatures_for_impl<
137+
::beman::execution26::detail::basic_sender<::beman::execution26::detail::on_t, Data, Sender>,
138+
Env> {
139+
//-dk:TODO pick up scheduler errors and merge them in?
140+
using type =
141+
#if 0
142+
::beman::execution26::detail::meta::combine<
143+
::beman::execution26::completion_signatures_of_t<Sender, Env>,
144+
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(::std::exception_ptr)>
145+
>
146+
#else
147+
::beman::execution26::completion_signatures<
148+
::beman::execution26::set_value_t(),
149+
::beman::execution26::set_error_t(::std::exception_ptr)
150+
>
151+
#endif
152+
;
75153
};
154+
#endif
155+
76156
} // namespace beman::execution26::detail
77157

78158
namespace beman::execution26 {

include/beman/execution26/detail/product_type.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <::std::size_t... I, typename... T>
2424
struct product_type_base<::std::index_sequence<I...>, T...>
2525
: ::beman::execution26::detail::product_type_element<I, T>... {
2626
static constexpr ::std::size_t size() { return sizeof...(T); }
27-
static constexpr bool is_product_type{true};
27+
static constexpr bool is_product_type{true};
2828

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

6969
template <typename T>
70-
concept is_product_type_c = requires(T const& t){ T::is_product_type; };
71-
70+
concept is_product_type_c = requires(const T& t) { T::is_product_type; };
7271

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

116115
namespace std {
117116
template <typename T>
118-
requires ::beman::execution26::detail::is_product_type_c<T>
119-
struct tuple_size<T>
120-
: ::std::integral_constant<std::size_t, T::size()> {};
117+
requires ::beman::execution26::detail::is_product_type_c<T>
118+
struct tuple_size<T> : ::std::integral_constant<std::size_t, T::size()> {};
121119

122120
template <::std::size_t I, typename T>
123-
requires ::beman::execution26::detail::is_product_type_c<T>
121+
requires ::beman::execution26::detail::is_product_type_c<T>
124122
struct tuple_element<I, T> {
125-
using type =
126-
::std::decay_t<decltype(::std::declval<T>().template get<I>())>;
123+
using type = ::std::decay_t<decltype(::std::declval<T>().template get<I>())>;
127124
};
128125
} // namespace std
129126

include/beman/execution26/detail/schedule_from.hpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHEDULE_FROM
66

77
#include <beman/execution26/detail/child_type.hpp>
8+
#include <beman/execution26/detail/meta_combine.hpp>
89
#include <beman/execution26/detail/completion_signatures_of_t.hpp>
910
#include <beman/execution26/detail/connect.hpp>
1011
#include <beman/execution26/detail/decayed_tuple.hpp>
1112
#include <beman/execution26/detail/default_domain.hpp>
1213
#include <beman/execution26/detail/default_impls.hpp>
14+
#include <beman/execution26/detail/error_types_of_t.hpp>
1315
#include <beman/execution26/detail/env_of_t.hpp>
1416
#include <beman/execution26/detail/fwd_env.hpp>
1517
#include <beman/execution26/detail/get_domain.hpp>
@@ -144,10 +146,15 @@ struct impls_for<::beman::execution26::detail::schedule_from_t> : ::beman::execu
144146
::std::monostate,
145147
::beman::execution26::detail::meta::transform<
146148
::beman::execution26::detail::as_tuple_t,
147-
::beman::execution26::detail::meta::to<::std::variant,
148-
::beman::execution26::completion_signatures_of_t<
149-
::beman::execution26::detail::child_type<Sender>,
150-
::beman::execution26::env_of_t<Receiver>>>>>>;
149+
::beman::execution26::detail::meta::to<
150+
::std::variant,
151+
::beman::execution26::detail::meta::combine<
152+
::beman::execution26::completion_signatures_of_t<
153+
::beman::execution26::detail::child_type<Sender>,
154+
::beman::execution26::env_of_t<Receiver>>,
155+
//-dk:TODO get proper error completion signatures
156+
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(
157+
::std::exception_ptr)>>>>>>;
151158

152159
return state_type<Receiver, sched_t, variant_t>(sch, receiver);
153160
}};
@@ -176,8 +183,15 @@ template <typename Scheduler, typename Sender, typename Env>
176183
struct completion_signatures_for_impl<
177184
::beman::execution26::detail::basic_sender<::beman::execution26::detail::schedule_from_t, Scheduler, Sender>,
178185
Env> {
179-
using type =
180-
decltype(::beman::execution26::get_completion_signatures(::std::declval<Sender>(), ::std::declval<Env>()));
186+
using scheduler_sender = decltype(::beman::execution26::schedule(::std::declval<Scheduler>()));
187+
template <typename... E>
188+
using as_set_error = ::beman::execution26::completion_signatures<::beman::execution26::set_error_t(E)...>;
189+
using type = ::beman::execution26::detail::meta::combine<
190+
decltype(::beman::execution26::get_completion_signatures(::std::declval<Sender>(), ::std::declval<Env>())),
191+
::beman::execution26::error_types_of_t<scheduler_sender, Env, as_set_error>,
192+
::beman::execution26::completion_signatures<::beman::execution26::set_error_t(
193+
::std::exception_ptr)> //-dk:TODO this one should be deduced
194+
>;
181195
};
182196
} // namespace beman::execution26::detail
183197

include/beman/execution26/detail/transform_sender.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
1616
requires(Domain dom, Sender&& sender, const Env&... env) {
1717
dom.transform_sender(::std::forward<Sender>(sender), env...);
1818
} &&
19-
(::std::same_as<
20-
::std::remove_cvref_t<Sender>,
21-
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
19+
(::std::same_as<::std::remove_cvref_t<Sender>,
20+
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
21+
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
2222
constexpr auto transform_sender(Domain, Sender&& sender, const Env&...) noexcept -> ::beman::execution26::sender auto {
2323
return ::std::forward<Sender>(sender);
2424
}
@@ -28,9 +28,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
2828
requires(Domain dom, Sender&& sender, const Env&... env) {
2929
dom.transform_sender(::std::forward<Sender>(sender), env...);
3030
} &&
31-
(not::std::same_as<
32-
::std::remove_cvref_t<Sender>,
33-
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
31+
(not::std::same_as<::std::remove_cvref_t<Sender>,
32+
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
33+
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
3434
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept
3535
-> ::beman::execution26::sender decltype(auto) {
3636
return ::beman::execution26::detail::transform_sender(
@@ -60,7 +60,6 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
6060
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept(noexcept(
6161
::beman::execution26::default_domain{}.transform_sender(::std::declval<Sender>(), ::std::declval<Env>()...)))
6262
-> ::beman::execution26::sender decltype(auto) {
63-
(void)dom;
6463
return ::beman::execution26::detail::transform_sender(
6564
dom, ::beman::execution26::default_domain{}.transform_sender(::std::forward<Sender>(sender), env...), env...);
6665
}
@@ -72,9 +71,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
7271
requires(Domain dom, Sender&& sender, const Env&... env) {
7372
dom.transform_sender(::std::forward<Sender>(sender), env...);
7473
} &&
75-
(::std::same_as<
76-
::std::remove_cvref_t<Sender>,
77-
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
74+
(::std::same_as<::std::remove_cvref_t<Sender>,
75+
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
76+
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
7877
constexpr auto transform_sender(Domain, Sender&& sender, const Env&...) noexcept -> ::beman::execution26::sender
7978
decltype(auto) {
8079
return ::std::forward<Sender>(sender);
@@ -85,9 +84,9 @@ template <typename Domain, ::beman::execution26::sender Sender, typename... Env>
8584
requires(Domain dom, Sender&& sender, const Env&... env) {
8685
dom.transform_sender(::std::forward<Sender>(sender), env...);
8786
} &&
88-
(not::std::same_as<
89-
::std::remove_cvref_t<Sender>,
90-
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(::std::declval<Sender>()))>>)
87+
(not::std::same_as<::std::remove_cvref_t<Sender>,
88+
std::remove_cvref_t<decltype(::std::declval<Domain>().transform_sender(
89+
::std::declval<Sender>(), ::std::declval<const Env&>()...))>>)
9190
constexpr auto transform_sender(Domain dom, Sender&& sender, const Env&... env) noexcept
9291
-> ::beman::execution26::sender auto {
9392
return ::beman::execution26::detail::transform_sender(

include/beman/execution26/execution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <beman/execution26/detail/into_variant.hpp>
4343
#include <beman/execution26/detail/just.hpp>
4444
#include <beman/execution26/detail/let.hpp>
45-
// #include <beman/execution26/detail/on.hpp>
45+
#include <beman/execution26/detail/on.hpp>
4646
#include <beman/execution26/detail/read_env.hpp>
4747
#include <beman/execution26/detail/schedule_from.hpp>
4848
#include <beman/execution26/detail/starts_on.hpp>

0 commit comments

Comments
 (0)