Skip to content

Commit

Permalink
avoid recursive template instatiation in then example
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed May 16, 2024
1 parent e1ef97f commit 300e791
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ struct _then_sender {
}

// Connect:
template <stdexec::receiver R>
template <stdexec::same_as<_then_sender> Self, stdexec::receiver R>
requires stdexec::sender_to<S, _then_receiver<R, F>>
STDEXEC_MEMFN_DECL(auto connect)(this _then_sender&& self, R r) {
STDEXEC_MEMFN_DECL(
auto connect)(this Self&& self, R r) {
return stdexec::connect(
static_cast<S&&>(self.s_),
_then_receiver<R, F>{static_cast<R&&>(r), static_cast<F&&>(self.f_)});
Expand Down
22 changes: 14 additions & 8 deletions include/stdexec/__detail/__receiver_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ namespace stdexec {
template <class _Self>
using __base_from_derived_t = decltype(__declval<_Self>().base());

using __get_base_t =
using __get_base_fn =
__if_c<__has_base, __mbind_back_q<__copy_cvref_t, _Base>, __q<__base_from_derived_t>>;

template <class _Self>
using __base_t = __minvoke<__get_base_t, _Self&&>;
using __base_t = __minvoke<__get_base_fn, _Self&&>;

template <class _Self>
STDEXEC_ATTRIBUTE((host, device))
Expand All @@ -140,27 +140,33 @@ namespace stdexec {
template <class... _As, class _Self = _Derived>
requires __callable<set_value_t, __base_t<_Self>, _As...>
STDEXEC_ATTRIBUTE((host, device))
void set_value(_As&&... __as) && noexcept {
return stdexec::set_value(__get_base(static_cast<_Self&&>(*this)), static_cast<_As&&>(__as)...);
void
set_value(_As&&... __as) && noexcept {
return stdexec::set_value(
__get_base(static_cast<_Self&&>(*this)), static_cast<_As&&>(__as)...);
}

template <class _Error, class _Self = _Derived>
requires __callable<set_error_t, __base_t<_Self>, _Error>
STDEXEC_ATTRIBUTE((host, device))
void set_error(_Error&& __err) && noexcept {
return stdexec::set_error(__get_base(static_cast<_Self&&>(*this)), static_cast<_Error&&>(__err));
void
set_error(_Error&& __err) && noexcept {
return stdexec::set_error(
__get_base(static_cast<_Self&&>(*this)), static_cast<_Error&&>(__err));
}

template <class _Self = _Derived>
requires __callable<set_stopped_t, __base_t<_Self>>
STDEXEC_ATTRIBUTE((host, device))
void set_stopped() && noexcept {
void
set_stopped() && noexcept {
return stdexec::set_stopped(__get_base(static_cast<_Self&&>(*this)));
}

template <class _Self = _Derived>
STDEXEC_ATTRIBUTE((host, device))
auto get_env() const noexcept -> env_of_t<__base_t<const _Self&>> {
auto
get_env() const noexcept -> env_of_t<__base_t<const _Self&>> {
return stdexec::get_env(__get_base(static_cast<const _Self&>(*this)));
}
};
Expand Down

0 comments on commit 300e791

Please sign in to comment.