Skip to content

Commit

Permalink
member-ify connect (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler authored Jul 10, 2024
1 parent 279705b commit 3845c59
Show file tree
Hide file tree
Showing 46 changed files with 233 additions and 283 deletions.
8 changes: 3 additions & 5 deletions examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ struct _then_sender {
}

// Connect:
template <stdexec::same_as<_then_sender> Self, stdexec::receiver R>
template <stdexec::receiver R>
requires stdexec::sender_to<S, _then_receiver<R, F>>
STDEXEC_MEMFN_DECL(
auto connect)(this Self&& self, R r) {
auto connect(R r) && {
return stdexec::connect(
static_cast<S&&>(self.s_),
_then_receiver<R, F>{static_cast<R&&>(r), static_cast<F&&>(self.f_)});
static_cast<S&&>(s_), _then_receiver<R, F>{static_cast<R&&>(r), static_cast<F&&>(f_)});
}

auto get_env() const noexcept -> decltype(auto) {
Expand Down
20 changes: 12 additions & 8 deletions include/exec/any_sender_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,7 @@ namespace exec {
}
};

class __t {
public:
struct __t {
using __id = __sender;
using completion_signatures = _Sigs;
using sender_concept = stdexec::sender_t;
Expand Down Expand Up @@ -1022,14 +1021,14 @@ namespace exec {
return {__storage_.__get_vtable(), __storage_.__get_object_pointer()};
}

private:
__unique_storage_t<__vtable> __storage_;

template <receiver_of<_Sigs> _Rcvr>
STDEXEC_MEMFN_DECL(auto connect)(this __t&& __self, _Rcvr&& __rcvr)
-> stdexec::__t<__operation<stdexec::__id<__decay_t<_Rcvr>>, __with_inplace_stop_token>> {
return {static_cast<__t&&>(__self), static_cast<_Rcvr&&>(__rcvr)};
auto connect(_Rcvr __rcvr) && //
-> stdexec::__t<__operation<stdexec::__id<_Rcvr>, __with_inplace_stop_token>> {
return {static_cast<__t&&>(*this), static_cast<_Rcvr&&>(__rcvr)};
}

private:
__unique_storage_t<__vtable> __storage_;
};
};

Expand Down Expand Up @@ -1202,6 +1201,11 @@ namespace exec {
: __sender_(static_cast<_Sender&&>(__sender)) {
}

template <stdexec::receiver_of<_Completions> _Receiver>
auto connect(_Receiver __rcvr) && -> stdexec::connect_result_t<__sender_base, _Receiver> {
return static_cast<__sender_base&&>(__sender_).connect(static_cast<_Receiver&&>(__rcvr));
}

template <auto... _SchedulerQueries>
class any_scheduler {
using __schedule_completions = stdexec::__concat_completion_signatures<
Expand Down
11 changes: 7 additions & 4 deletions include/exec/async_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ namespace exec {

template <__decays_to<__t> _Self, receiver _Receiver>
requires sender_to<__copy_cvref_t<_Self, _Constrained>, _Receiver>
[[nodiscard]] STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Receiver __rcvr) -> __when_empty_op_t<_Self, _Receiver> {
[[nodiscard]]
static auto connect(_Self&& __self, _Receiver __rcvr) //
-> __when_empty_op_t<_Self, _Receiver> {
return __when_empty_op_t<_Self, _Receiver>{
__self.__scope_, static_cast<_Self&&>(__self).__c_, static_cast<_Receiver&&>(__rcvr)};
}
Expand Down Expand Up @@ -251,7 +253,8 @@ namespace exec {

template <__decays_to<__t> _Self, receiver _Receiver>
requires sender_to<__copy_cvref_t<_Self, _Constrained>, __nest_receiver_t<_Receiver>>
[[nodiscard]] STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Receiver __rcvr) -> __nest_operation_t<_Receiver> {
[[nodiscard]]
static auto connect(_Self&& __self, _Receiver __rcvr) -> __nest_operation_t<_Receiver> {
return __nest_operation_t<_Receiver>{
__self.__scope_, static_cast<_Self&&>(__self).__c_, static_cast<_Receiver&&>(__rcvr)};
}
Expand Down Expand Up @@ -635,9 +638,9 @@ namespace exec {

template <__decays_to<__t> _Self, receiver _Receiver>
requires receiver_of<_Receiver, __completions_t<_Self>>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Receiver __rcvr) -> __future_op_t<_Receiver> {
static auto connect(_Self&& __self, _Receiver __rcvr) -> __future_op_t<_Receiver> {
return __future_op_t<_Receiver>{
static_cast<_Receiver&&>(__rcvr), std::move(__self.__state_)};
static_cast<_Receiver&&>(__rcvr), static_cast<_Self&&>(__self).__state_};
}

template <__decays_to<__t> _Self, class... _OtherEnv>
Expand Down
10 changes: 4 additions & 6 deletions include/exec/at_coroutine_exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ namespace exec {

template <receiver _Receiver>
requires sender_to<_Sender, __receiver<_Receiver>>
STDEXEC_MEMFN_DECL(
auto connect)(this __t&& __self, _Receiver&& __rcvr) noexcept
auto connect(_Receiver __rcvr) && noexcept
-> connect_result_t<_Sender, __receiver<_Receiver>> {
return stdexec::connect(
static_cast<_Sender&&>(__self.__sender_),
static_cast<_Sender&&>(__sender_),
__receiver<_Receiver>{static_cast<_Receiver&&>(__rcvr)});
}

template <__decays_to<__t> _Self, class... _Env>
static auto
get_completion_signatures(_Self&&, _Env&&...) -> __completion_signatures<_Env...> {
template <class... _Env>
auto get_completion_signatures(_Env&&...) -> __completion_signatures<_Env...> {
return {};
}

Expand Down
7 changes: 3 additions & 4 deletions include/exec/create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ namespace exec {

template <__decays_to<__t> _Self, receiver_of<completion_signatures> _Receiver>
requires __callable<_Fun, __context<_Receiver, _Args>&>
&& constructible_from<_Fun, __copy_cvref_t<_Self, _Fun>>
&& constructible_from<_Args, __copy_cvref_t<_Self, _Args>>
STDEXEC_MEMFN_DECL(
auto connect)(this _Self&& __self, _Receiver __rcvr)
&& constructible_from<_Fun, __copy_cvref_t<_Self, _Fun>>
&& constructible_from<_Args, __copy_cvref_t<_Self, _Args>>
static auto connect(_Self&& __self, _Receiver __rcvr)
-> stdexec::__t<__operation<stdexec::__id<_Receiver>, _Fun, _ArgsId>> {
static_assert(__nothrow_callable<_Fun, __context<_Receiver, _Args>&>);
return {
Expand Down
3 changes: 1 addition & 2 deletions include/exec/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ namespace exec {

template <__decays_to<__sender> _Self, class _Receiver>
requires receiver_of<_Receiver, __completions_t<env_of_t<_Receiver>>>
STDEXEC_MEMFN_DECL(
auto connect)(this _Self&& __self, _Receiver __rcvr) //
static auto connect(_Self&& __self, _Receiver __rcvr) //
noexcept(std::is_nothrow_move_constructible_v<_Receiver>)
-> __operation_t<_Tag, __default_t<env_of_t<_Receiver>>, _Receiver> {
return {{}, static_cast<_Self&&>(__self).__default_, static_cast<_Receiver&&>(__rcvr)};
Expand Down
2 changes: 1 addition & 1 deletion include/exec/finally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _Rec>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Rec&& __receiver) noexcept -> __op_t<_Self, _Rec> {
static auto connect(_Self&& __self, _Rec&& __receiver) noexcept -> __op_t<_Self, _Rec> {
return {
static_cast<_Self&&>(__self).__initial_sndr_,
static_cast<_Self&&>(__self).__final_sndr_,
Expand Down
15 changes: 3 additions & 12 deletions include/exec/libdispatch_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,10 @@ namespace exec {
using completion_signatures =
stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_stopped_t()>;

template <typename Receiver>
auto make_operation(Receiver r) const
-> __libdispatch_details::operation<stdexec::__id<Receiver>> {
return __libdispatch_details::operation<stdexec::__id<Receiver>>(queue, std::move(r));
}

STDEXEC_MEMFN_FRIEND(connect);

template <stdexec::receiver Receiver>
STDEXEC_MEMFN_DECL(auto connect)(this sender s, Receiver r)
auto connect(Receiver r) const //
-> __libdispatch_details::operation<stdexec::__id<Receiver>> {
return s.make_operation(std::move(r));
return __libdispatch_details::operation<stdexec::__id<Receiver>>(queue, std::move(r));
}

struct env {
Expand Down Expand Up @@ -297,8 +289,7 @@ namespace exec {

template <stdexec::__decays_to<__t> Self, stdexec::receiver Receiver>
requires stdexec::receiver_of<Receiver, __completions_t<Self, stdexec::env_of_t<Receiver>>>
STDEXEC_MEMFN_DECL(
bulk_op_state_t<Self, Receiver> connect)(this Self &&self, Receiver rcvr) //
static bulk_op_state_t<Self, Receiver> connect(Self &&self, Receiver rcvr) //
noexcept(stdexec::__nothrow_constructible_from<
bulk_op_state_t<Self, Receiver>,
libdispatch_queue &,
Expand Down
24 changes: 9 additions & 15 deletions include/exec/linux/io_uring_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ namespace exec {
stdexec::set_error_t(std::exception_ptr),
stdexec::set_stopped_t()>;

template <stdexec::receiver_of<completion_signatures> _Rcvr>
auto connect(_Rcvr __rcvr) const noexcept -> __run_op<_Rcvr> {
return {static_cast<_Rcvr&&>(__rcvr), *__context_, __mode_};
}

private:
friend class __context;
__context* __context_;
Expand All @@ -595,14 +600,6 @@ namespace exec {
: __context_{__context}
, __mode_{__mode} {
}

template <
stdexec::__decays_to<__run_sender> _Self,
stdexec::receiver_of<completion_signatures> _Rcvr>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Rcvr&& __rcvr) noexcept
-> __run_op<stdexec::__decay_t<_Rcvr>> {
return {static_cast<_Rcvr&&>(__rcvr), *__self.__context_, __self.__mode_};
}
};

auto run(until __mode = until::stopped) -> __run_sender {
Expand Down Expand Up @@ -1101,10 +1098,10 @@ namespace exec {
}

template <stdexec::receiver_of<__completion_sigs> _Receiver>
STDEXEC_MEMFN_DECL(auto connect)(this const __schedule_sender& __sender, _Receiver&& __receiver)
auto connect(_Receiver __receiver) const & //
-> stdexec::__t<__schedule_operation<stdexec::__id<_Receiver>>> {
return stdexec::__t<__schedule_operation<stdexec::__id<_Receiver>>>(
std::in_place, *__sender.__env_.__context_, static_cast<_Receiver&&>(__receiver));
std::in_place, *__env_.__context_, static_cast<_Receiver&&>(__receiver));
}
};

Expand Down Expand Up @@ -1133,13 +1130,10 @@ namespace exec {
}

template <stdexec::receiver_of<__completion_sigs> _Receiver>
STDEXEC_MEMFN_DECL(auto connect)(this const __schedule_after_sender& __sender, _Receiver&& __receiver)
auto connect(_Receiver __receiver) const & //
-> stdexec::__t<__schedule_after_operation<stdexec::__id<_Receiver>>> {
return stdexec::__t<__schedule_after_operation<stdexec::__id<_Receiver>>>(
std::in_place,
*__sender.__env_.__context_,
__sender.__duration_,
static_cast<_Receiver&&>(__receiver));
std::in_place, *__env_.__context_, __duration_, static_cast<_Receiver&&>(__receiver));
}
};

Expand Down
6 changes: 2 additions & 4 deletions include/exec/materialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ namespace exec {

template <__decays_to<__t> _Self, class _Receiver>
requires sender_to<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>>
STDEXEC_MEMFN_DECL(
auto connect)(this _Self&& __self, _Receiver&& __receiver) //
static auto connect(_Self&& __self, _Receiver __receiver) //
noexcept(__nothrow_connectable<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>>)
-> connect_result_t<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>> {
return stdexec::connect(
Expand Down Expand Up @@ -191,8 +190,7 @@ namespace exec {

template <__decays_to<__t> _Self, class _Receiver>
requires sender_to<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>>
STDEXEC_MEMFN_DECL(
auto connect)(this _Self&& __self, _Receiver&& __receiver) //
static auto connect(_Self&& __self, _Receiver __receiver) //
noexcept(__nothrow_connectable<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>>)
-> connect_result_t<__copy_cvref_t<_Self, _Sender>, __receiver_t<_Receiver>> {
return stdexec::connect(
Expand Down
3 changes: 1 addition & 2 deletions include/exec/reschedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ namespace exec {

template <receiver _Receiver>
requires receiver_of<_Receiver, __completions<env_of_t<_Receiver>>>
STDEXEC_MEMFN_DECL(
auto connect)(this __sender, _Receiver __rcvr)
auto connect(_Receiver __rcvr) const
-> connect_result_t<__schedule_sender_t<env_of_t<_Receiver>>, _Receiver> {
auto __sched = get_scheduler(get_env(__rcvr));
return stdexec::connect(schedule(__sched), static_cast<_Receiver&&>(__rcvr));
Expand Down
5 changes: 2 additions & 3 deletions include/exec/sequence/empty_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ namespace exec {
using item_types = exec::item_types<>;

template <__decays_to<__t> _Self, receiver_of<completion_signatures> _Rcvr>
STDEXEC_MEMFN_DECL(auto subscribe)(this _Self&&, _Rcvr&& __rcvr) noexcept(__nothrow_decay_copyable<_Rcvr>) {
return stdexec::__t<__operation<stdexec::__id<__decay_t<_Rcvr>>>>{
static_cast<_Rcvr&&>(__rcvr)};
STDEXEC_MEMFN_DECL(auto subscribe)(this _Self&&, _Rcvr __rcvr) noexcept(__nothrow_move_constructible<_Rcvr>) {
return stdexec::__t<__operation<stdexec::__id<_Rcvr>>>{static_cast<_Rcvr&&>(__rcvr)};
}
};
};
Expand Down
5 changes: 2 additions & 3 deletions include/exec/sequence/ignore_all_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace exec {

template <__decays_to<__t> _Self, stdexec::receiver_of<completion_signatures> _Receiver>
requires sender_to<__copy_cvref_t<_Self, _Sender>, __item_receiver_t<_Receiver>>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Receiver __rcvr) -> __operation_t<_Self, _Receiver> {
static auto connect(_Self&& __self, _Receiver __rcvr) -> __operation_t<_Self, _Receiver> {
return {
__self.__parent_,
static_cast<_Self&&>(__self).__sender_,
Expand Down Expand Up @@ -243,8 +243,7 @@ namespace exec {

subscribe_result_t<_Sender, __receiver_t> __op_;

__t(_Sender&& __sndr, _Receiver __rcvr) //
noexcept(__nothrow_decay_copyable<_Receiver>)
__t(_Sender&& __sndr, _Receiver __rcvr) noexcept(__nothrow_move_constructible<_Receiver>)
: __base_type{{}, static_cast<_Receiver&&>(__rcvr)}
, __op_{exec::subscribe(static_cast<_Sender&&>(__sndr), __receiver_t{this})} {
}
Expand Down
11 changes: 5 additions & 6 deletions include/exec/sequence/iterate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ namespace exec {
stdexec::completion_signatures<set_value_t(std::iter_reference_t<_Iterator>)>;
__operation_base<_Iterator, _Sentinel>* __parent_;

template <__decays_to<__t> _Self, receiver_of<completion_signatures> _ItemRcvr>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _ItemRcvr __rcvr) //
noexcept(__nothrow_decay_copyable<_ItemRcvr>)
-> stdexec::__t<__item_operation<_Iterator, _Sentinel, _ItemRcvr>> {
return {static_cast<_ItemRcvr&&>(__rcvr), __self.__parent_};
template <receiver_of<completion_signatures> _ItemRcvr>
auto connect(_ItemRcvr __rcvr) const & noexcept(__nothrow_decay_copyable<_ItemRcvr>)
-> stdexec::__t<__item_operation<_Iterator, _Sentinel, _ItemRcvr>> {
return {static_cast<_ItemRcvr&&>(__rcvr), __parent_};
}
};
};
Expand Down Expand Up @@ -157,7 +156,7 @@ namespace exec {

template <class _Range>
auto operator()(__ignore, _Range&& __range) //
noexcept(__nothrow_decay_copyable<_Receiver>) -> __operation_t<_Range> {
noexcept(__nothrow_move_constructible<_Receiver>) -> __operation_t<_Range> {
return {
{std::ranges::begin(__range), std::ranges::end(__range)},
static_cast<_Receiver&&>(__rcvr_)
Expand Down
2 changes: 1 addition & 1 deletion include/exec/sequence/transform_each.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace exec {
auto operator()(__ignore, _Adaptor __adaptor, _Sequence&& __sequence) //
noexcept(
__nothrow_decay_copyable<_Adaptor> && __nothrow_decay_copyable<_Sequence>
&& __nothrow_decay_copyable<_Receiver>)
&& __nothrow_move_constructible<_Receiver>)
-> __t<__operation<_Sequence, __id<_Receiver>, _Adaptor>> {
return {
static_cast<_Sequence&&>(__sequence),
Expand Down
Loading

0 comments on commit 3845c59

Please sign in to comment.