Skip to content

Commit f146a8f

Browse files
authored
a simpler implementation for stdexec::__tuple (#1717)
* clean up sender adaptor closures * stop being so precious with the execution policies
1 parent aab07dd commit f146a8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+623
-539
lines changed

include/exec/finally.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ namespace exec {
304304

305305
template <sender _Final>
306306
STDEXEC_ATTRIBUTE(always_inline)
307-
auto operator()(_Final&& __final) const -> __binder_back<finally_t, __decay_t<_Final>> {
308-
return {{static_cast<_Final&&>(__final)}, {}, {}};
307+
auto operator()(_Final&& __final) const {
308+
return __closure(*this, static_cast<_Final&&>(__final));
309309
}
310310

311311
template <class _Sender>

include/exec/fork_join.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace exec {
3939
template <class Rcvr, class Tuple>
4040
STDEXEC_ATTRIBUTE(always_inline, host, device)
4141
void operator()(Rcvr& rcvr, const Tuple& tupl) const noexcept {
42-
tupl.apply(_impl_fn{}, tupl, rcvr);
42+
stdexec::__apply(_impl_fn{}, tupl, rcvr);
4343
}
4444
};
4545

@@ -55,7 +55,7 @@ namespace exec {
5555
using _maybe_eptr_completion_t = stdexec::__if_c<
5656
stdexec::__nothrow_decay_copyable_results_t<Completions>::value,
5757
stdexec::__mset_nil,
58-
stdexec::__tuple_for<stdexec::set_error_t, ::std::exception_ptr>
58+
stdexec::__tuple<stdexec::set_error_t, ::std::exception_ptr>
5959
>;
6060

6161
template <class Completions>
@@ -122,7 +122,7 @@ namespace exec {
122122
};
123123

124124
template <class Completions, class Closures, class Domain>
125-
using _when_all_sndr_t = stdexec::__tup::__apply_result_t<
125+
using _when_all_sndr_t = stdexec::__apply_result_t<
126126
_mk_when_all_fn,
127127
Closures,
128128
_cache_sndr_t<_variant_t<Completions>, Domain>
@@ -147,7 +147,7 @@ namespace exec {
147147
: _rcvr_(static_cast<Rcvr&&>(rcvr))
148148
, _fork_opstate_(
149149
stdexec::connect(
150-
closures.apply(
150+
stdexec::__apply(
151151
_mk_when_all_fn{},
152152
static_cast<Closures&&>(closures),
153153
_cache_sndr_t{&_cache_}),
@@ -178,7 +178,7 @@ namespace exec {
178178
}
179179
STDEXEC_CATCH_ALL {
180180
if constexpr (!stdexec::__nothrow_decay_copyable<Args...>) {
181-
using _tuple_t = stdexec::__tuple_for<stdexec::set_error_t, ::std::exception_ptr>;
181+
using _tuple_t = stdexec::__tuple<stdexec::set_error_t, ::std::exception_ptr>;
182182
_cache_._results_
183183
.template emplace<_tuple_t>(stdexec::set_error, ::std::current_exception());
184184
}
@@ -216,7 +216,7 @@ namespace exec {
216216

217217
template <class... Closures>
218218
struct _closure_t {
219-
using _closures_t = stdexec::__tuple_for<Closures...>;
219+
using _closures_t = stdexec::__tuple<Closures...>;
220220

221221
template <class Sndr>
222222
STDEXEC_ATTRIBUTE(host, device)
@@ -250,7 +250,7 @@ namespace exec {
250250
template <class Sndr, class... Closures>
251251
struct fork_join_t::_sndr_t {
252252
using sender_concept = stdexec::sender_t;
253-
using _closures_t = stdexec::__tuple_for<Closures...>;
253+
using _closures_t = stdexec::__tuple<Closures...>;
254254

255255
template <class Self, class... Env>
256256
STDEXEC_ATTRIBUTE(host, device)
@@ -297,7 +297,7 @@ namespace exec {
297297
}
298298

299299
STDEXEC_ATTRIBUTE(no_unique_address) fork_join_t _tag_;
300-
stdexec::__tuple_for<Closures...> _closures_;
300+
stdexec::__tuple<Closures...> _closures_;
301301
Sndr sndr_;
302302
};
303303

include/exec/into_tuple.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ namespace exec {
101101
}
102102

103103
STDEXEC_ATTRIBUTE(always_inline)
104-
constexpr auto operator()() const noexcept -> __binder_back<into_tuple_t> {
105-
return {{}, {}, {}};
104+
constexpr auto operator()() const noexcept {
105+
return __closure(*this);
106106
}
107107
};
108108
} // namespace __into_tuple

include/exec/materialize.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ namespace exec {
123123
}
124124

125125
STDEXEC_ATTRIBUTE(always_inline)
126-
auto operator()() const noexcept -> __binder_back<__materialize_t> {
127-
return {{}, {}, {}};
126+
auto operator()() const noexcept {
127+
return __closure(*this);
128128
}
129129
};
130130
} // namespace __materialize
@@ -233,8 +233,8 @@ namespace exec {
233233
}
234234

235235
STDEXEC_ATTRIBUTE(always_inline)
236-
auto operator()() const noexcept -> __binder_back<__dematerialize_t> {
237-
return {{}, {}, {}};
236+
auto operator()() const noexcept {
237+
return __closure(*this);
238238
}
239239
};
240240
} // namespace __dematerialize

include/exec/repeat_effect_until.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ namespace exec {
204204
}
205205

206206
STDEXEC_ATTRIBUTE(always_inline)
207-
constexpr auto operator()() const -> __binder_back<repeat_effect_until_t> {
208-
return {{}, {}, {}};
207+
constexpr auto operator()() const {
208+
return __closure(*this);
209209
}
210210

211211
template <class _Sender>
@@ -232,8 +232,8 @@ namespace exec {
232232
}
233233

234234
STDEXEC_ATTRIBUTE(always_inline)
235-
constexpr auto operator()() const -> __binder_back<repeat_effect_t> {
236-
return {{}, {}, {}};
235+
constexpr auto operator()() const {
236+
return __closure(*this);
237237
}
238238

239239
template <class _Sender>

include/exec/repeat_n.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ namespace exec {
202202
}
203203

204204
STDEXEC_ATTRIBUTE(always_inline)
205-
constexpr auto
206-
operator()(std::size_t __count) const -> __binder_back<repeat_n_t, std::size_t> {
207-
return {{__count}, {}, {}};
205+
constexpr auto operator()(std::size_t __count) const noexcept {
206+
return __closure(*this, __count);
208207
}
209208

210209
template <class _Sender, bool _NoThrow = __nothrow_decay_copyable<_Sender>>

include/exec/sequence.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ namespace exec {
6666
}
6767
};
6868

69+
template <class _Tuple>
70+
struct __convert_tuple_fn {
71+
template <class... _Ts>
72+
STDEXEC_ATTRIBUTE(host, device, always_inline)
73+
constexpr auto
74+
operator()(_Ts&&... __ts) const STDEXEC_AUTO_RETURN(_Tuple{static_cast<_Ts&&>(__ts)...});
75+
};
76+
6977
template <class Rcvr, class... Sndrs>
7078
struct _opstate;
7179

@@ -76,7 +84,7 @@ namespace exec {
7684
// We will be connecting the first sender in the opstate constructor, so we don't need to
7785
// store it in the opstate. The use of `stdexec::__ignore` causes the first sender to not
7886
// be stored.
79-
using _senders_tuple_t = stdexec::__tuple_for<stdexec::__ignore, Sndrs...>;
87+
using _senders_tuple_t = stdexec::__tuple<stdexec::__ignore, Sndrs...>;
8088

8189
template <size_t Idx>
8290
using _rcvr_t = _seq::_rcvr<Rcvr, stdexec::__id<_opstate>, stdexec::__msize_t<Idx>>;
@@ -91,24 +99,23 @@ namespace exec {
9199

92100
using _ops_variant_t = stdexec::__minvoke<
93101
_mk_child_ops_variant_fn,
94-
stdexec::__tuple_for<Sndr0, Sndrs...>,
102+
stdexec::__tuple<Sndr0, Sndrs...>,
95103
stdexec::__make_indices<sizeof...(Sndrs) + 1>
96104
>;
97105

98106
template <class CvrefSndrs>
99107
STDEXEC_ATTRIBUTE(host, device)
100108
explicit _opstate(Rcvr&& rcvr, CvrefSndrs&& sndrs)
101109
: _rcvr{static_cast<Rcvr&&>(rcvr)}
102-
, _sndrs{_senders_tuple_t::__convert_from(static_cast<CvrefSndrs&&>(sndrs))}
103-
// move all but the first sender into the opstate.
110+
, _sndrs{stdexec::__apply(
111+
__convert_tuple_fn<_senders_tuple_t>{},
112+
static_cast<CvrefSndrs&&>(sndrs))} // move all but the first sender into the opstate.
104113
{
105114
// Below, it looks like we are using `sndrs` after it has been moved from. This is not the
106115
// case. `sndrs` is moved into a tuple type that has `__ignore` for the first element. The
107116
// result is that the first sender in `sndrs` is not moved from, but the rest are.
108117
_ops.template emplace_from_at<0>(
109-
stdexec::connect,
110-
sndrs.template __get<0>(static_cast<CvrefSndrs&&>(sndrs)),
111-
_rcvr_t<0>{this});
118+
stdexec::connect, stdexec::__get<0>(static_cast<CvrefSndrs&&>(sndrs)), _rcvr_t<0>{this});
112119
}
113120

114121
template <class Index, class... Args>
@@ -119,7 +126,7 @@ namespace exec {
119126
if constexpr (Idx == sizeof...(Sndrs) + 1) {
120127
stdexec::set_value(static_cast<Rcvr&&>(_rcvr), static_cast<Args&&>(args)...);
121128
} else {
122-
auto& sndr = _sndrs.template __get<Idx>(_sndrs);
129+
auto& sndr = stdexec::__get<Idx>(_sndrs);
123130
auto& op = _ops.template emplace_from_at<Idx>(
124131
stdexec::connect, std::move(sndr), _rcvr_t<Idx>{this});
125132
stdexec::start(op);
@@ -206,7 +213,7 @@ namespace exec {
206213

207214
STDEXEC_ATTRIBUTE(no_unique_address, maybe_unused) sequence_t _tag;
208215
STDEXEC_ATTRIBUTE(no_unique_address, maybe_unused) stdexec::__ignore _ignore;
209-
stdexec::__tuple_for<Sndrs...> _sndrs;
216+
stdexec::__tuple<Sndrs...> _sndrs;
210217
};
211218

212219
template <class Sndr>

include/exec/sequence/ignore_all_values.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ namespace exec {
308308
}
309309

310310
STDEXEC_ATTRIBUTE(always_inline)
311-
constexpr auto operator()() const noexcept -> __binder_back<ignore_all_values_t> {
312-
return {{}, {}, {}};
311+
constexpr auto operator()() const noexcept {
312+
return __closure(*this);
313313
}
314314
};
315315

include/exec/sequence/merge.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace exec {
8282
struct __combine {
8383
template <class _ReceiverId>
8484
using merge_each_fn_t =
85-
__binder_back<__merge_each_fn<_ReceiverId>, __operation_base<__t<_ReceiverId>>*>;
85+
__closure<__merge_each_fn<_ReceiverId>, __operation_base<__t<_ReceiverId>>*>;
8686

8787
template <class _Sequence, class _ReceiverId>
8888
using transform_sender_t =
@@ -118,7 +118,7 @@ namespace exec {
118118
exec::ignore_all_values(
119119
exec::transform_each(
120120
static_cast<_Sequences&&>(__sequences),
121-
merge_each_fn_t{{this}, {}, {}}))...),
121+
merge_each_fn_t({}, this)))...),
122122
stdexec::__t<__result_receiver<_ReceiverId>>{this})} {
123123
}
124124

@@ -161,7 +161,6 @@ namespace exec {
161161

162162
template <class... _Env>
163163
struct __completions_fn_t {
164-
165164
template <class... _Sequences>
166165
using __f = __meval<
167166
__concat_completion_signatures,

include/exec/sequence/transform_each.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ namespace exec {
161161
template <class _Adaptor>
162162
STDEXEC_ATTRIBUTE(always_inline)
163163
constexpr auto
164-
operator()(_Adaptor __adaptor) const noexcept -> __binder_back<transform_each_t, _Adaptor> {
165-
return {{static_cast<_Adaptor&&>(__adaptor)}, {}, {}};
164+
operator()(_Adaptor&& __adaptor) const noexcept(__nothrow_decay_copyable<_Adaptor>) {
165+
return __closure(*this, static_cast<_Adaptor&&>(__adaptor));
166166
}
167167

168168
template <class _Self, class... _Env>

0 commit comments

Comments
 (0)