Skip to content

Commit

Permalink
port transfer_just to use transform_sender
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Oct 19, 2023
1 parent 31226b0 commit c1e26d7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
9 changes: 9 additions & 0 deletions include/stdexec/__detail/__execution_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ namespace stdexec {
}

using __transfer::transfer_t;
extern const transfer_t transfer;

//////////////////////////////////////////////////////////////////////////////////////////////////
namespace __transfer_just {
struct transfer_just_t;
}

using __transfer_just::transfer_just_t;
extern const transfer_just_t transfer_just;

//////////////////////////////////////////////////////////////////////////////////////////////////
namespace __on_v2 {
Expand Down
51 changes: 38 additions & 13 deletions include/stdexec/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5537,23 +5537,48 @@ namespace stdexec {
/////////////////////////////////////////////////////////////////////////////
// [execution.senders.transfer_just]
namespace __transfer_just {
inline auto __transfer_just_tag_invoke() {
return []<class... _Ts>(_Ts&&... __ts) -> tag_invoke_result_t<transfer_just_t, _Ts...> {
return tag_invoke(transfer_just, (_Ts&&) __ts...);
};
}

struct transfer_just_t {
using _Data = __0;
using __legacy_customizations_t = //
__types<__apply_t(decltype(__transfer_just_tag_invoke()), _Data)>;

template <scheduler _Scheduler, __movable_value... _Values>
requires tag_invocable<transfer_just_t, _Scheduler, _Values...>
&& sender<tag_invoke_result_t<transfer_just_t, _Scheduler, _Values...>>
auto operator()(_Scheduler&& __sched, _Values&&... __vals) const
noexcept(nothrow_tag_invocable<transfer_just_t, _Scheduler, _Values...>)
-> tag_invoke_result_t<transfer_just_t, _Scheduler, _Values...> {
return tag_invoke(*this, (_Scheduler&&) __sched, (_Values&&) __vals...);
auto operator()(_Scheduler&& __sched, _Values&&... __vals) const {
auto __domain = query_or(get_domain, __sched, default_domain());
return stdexec::transform_sender(
__domain,
make_sender_expr<transfer_just_t>(
std::tuple{(_Scheduler&&) __sched, (_Values&&) __vals...}));
}

template <scheduler _Scheduler, __movable_value... _Values>
requires(
!tag_invocable<transfer_just_t, _Scheduler, _Values...>
|| !sender<tag_invoke_result_t<transfer_just_t, _Scheduler, _Values...>>)
auto operator()(_Scheduler&& __sched, _Values&&... __vals) const
-> decltype(transfer(just((_Values&&) __vals...), (_Scheduler&&) __sched)) {
return transfer(just((_Values&&) __vals...), (_Scheduler&&) __sched);
template <sender_expr_for<transfer_just_t> _Sender>
static auto get_env(const _Sender& __sndr) noexcept {
return __apply(
[&]<class _Scheduler>(const _Scheduler& __sched, auto&&...) noexcept {
return __t<__schedule_from::__environ<__id<_Scheduler>>>{__sched};
},
apply_sender((_Sender&&) __sndr, __detail::__get_data()));
}

template <class _Sender, class _Env>
static auto transform_sender(_Sender&& __sndr, const _Env& __env) {
return __apply(
[&]<class _Scheduler, class... _Values>(_Scheduler&& __sched, _Values&&... __vals) {
auto __domain = __get_env_domain(__env);
return stdexec::transform_sender(
__domain,
transfer(
stdexec::transform_sender(__domain, just((_Values&&) __vals...), __env),
(_Scheduler&&) __sched),
__env);
},
apply_sender((_Sender&&) __sndr, __detail::__get_data()));
}
};
} // namespace __transfer_just
Expand Down

0 comments on commit c1e26d7

Please sign in to comment.