Skip to content

Commit 01607f1

Browse files
committed
add an exec::write_attrs sender adaptor
1 parent 4bb5927 commit 01607f1

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

include/exec/env.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,67 @@ namespace exec {
144144
[[deprecated("exec::write_env has been renamed to exec::write_env")]]
145145
inline constexpr stdexec::__write_::__write_env_t write{};
146146
inline constexpr stdexec::__write_::__write_env_t write_env{};
147+
148+
namespace __write_attrs {
149+
using namespace stdexec;
150+
151+
template <class _SenderId, class _Attrs>
152+
struct __sender {
153+
using _Sender = stdexec::__t<_SenderId>;
154+
155+
struct __t {
156+
using sender_concept = sender_t;
157+
using __id = __sender;
158+
_Sender __sndr_;
159+
_Attrs __attrs_;
160+
161+
auto get_env() const noexcept -> __env::__join_t<const _Attrs&, env_of_t<_Sender>> {
162+
return stdexec::__env::__join(__attrs_, stdexec::get_env(__sndr_));
163+
}
164+
165+
template <__decays_to<__t> _Self, class... _Env>
166+
static auto get_completion_signatures(_Self&&, _Env&&...)
167+
-> completion_signatures_of_t<__copy_cvref_t<_Self, _Sender>, _Env...> {
168+
return {};
169+
}
170+
171+
template <__decays_to<__t> _Self, class _Receiver>
172+
requires sender_in<__copy_cvref_t<_Self, _Sender>, env_of_t<_Receiver>>
173+
static auto connect(_Self&& __self, _Receiver __rcvr)
174+
-> connect_result_t<__copy_cvref_t<_Self, _Sender>, _Receiver> {
175+
return stdexec::connect(std::forward<_Self>(__self).__sndr_, std::move(__rcvr));
176+
}
177+
};
178+
};
179+
180+
struct __write_attrs_t {
181+
template <class _Sender, class _Attrs>
182+
STDEXEC_ATTRIBUTE((host, device)) auto operator()(_Sender snd, _Attrs __attrs_) const //
183+
-> __write_attrs::__sender<_Sender, _Attrs> {
184+
return __t<__write_attrs::__sender<__id<_Sender>, _Attrs>>{
185+
static_cast<_Sender&&>(snd), static_cast<_Attrs&&>(__attrs_)};
186+
}
187+
188+
template <class _Attrs>
189+
struct __closure {
190+
_Attrs __attrs_;
191+
192+
template <class _Sender>
193+
STDEXEC_ATTRIBUTE((host, device)) friend auto operator|(_Sender __sndr_, __closure _clsr) {
194+
return __t<__write_attrs::__sender<__id<_Sender>, _Attrs>>{
195+
static_cast<_Sender&&>(__sndr_), static_cast<_Attrs&&>(_clsr.__attrs_)};
196+
}
197+
};
198+
199+
template <class _Attrs>
200+
STDEXEC_ATTRIBUTE((host, device)) auto operator()(_Attrs __attrs_) const {
201+
return __closure<_Attrs>{static_cast<_Attrs&&>(__attrs_)};
202+
}
203+
};
204+
} // namespace __write_attrs
205+
206+
inline constexpr __write_attrs::__write_attrs_t write_attrs{};
207+
147208
} // namespace exec
148209

149210
STDEXEC_PRAGMA_POP()

0 commit comments

Comments
 (0)