-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy path__basic_sequence.hpp
More file actions
204 lines (185 loc) · 8.62 KB
/
__basic_sequence.hpp
File metadata and controls
204 lines (185 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright (c) 2023 NVIDIA Corporation
* Copyright (c) 2023 Maikel Nadolski
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "../../stdexec/__detail/__config.hpp"
#include "../../stdexec/__detail/__meta.hpp"
#include "../../stdexec/__detail/__basic_sender.hpp"
#include "../sequence_senders.hpp"
#include "../../stdexec/__detail/__completion_signatures.hpp"
#include "../../stdexec/__detail/__concepts.hpp"
#include "../../stdexec/__detail/__debug.hpp"
#include <type_traits>
namespace exec {
//////////////////////////////////////////////////////////////////////////////////////////////////
// __seqexpr
template <class...>
struct __basic_sequence_sender {
using __id = __basic_sequence_sender;
using __t = __basic_sequence_sender;
};
template <auto _DescriptorFn, class = stdexec::__anon>
struct __seqexpr {
using sender_concept = sequence_sender_t;
using __t = __seqexpr;
using __id = __seqexpr;
using __desc_t = decltype(_DescriptorFn());
using __tag_t = __desc_t::__tag;
using __captures_t =
stdexec::__minvoke<__desc_t, stdexec::__q<stdexec::__detail::__captures_t>>;
static constexpr auto __tag() noexcept -> __tag_t {
return {};
}
mutable __captures_t __impl_;
template <class _Tag, class _Data, class... _Child>
STDEXEC_ATTRIBUTE(host, device)
explicit __seqexpr(_Tag, _Data&& __data, _Child&&... __child)
: __impl_(
stdexec::__detail::__captures(
_Tag(),
static_cast<_Data&&>(__data),
static_cast<_Child&&>(__child)...)) {
}
template <stdexec::same_as<__seqexpr> _Self = __seqexpr>
auto get_env() const noexcept -> decltype(_Self::__tag().get_env(*this)) {
static_assert(noexcept(_Self::__tag().get_env(*this)));
return _Self::__tag().get_env(*this);
}
// make sure that get_completion_signatures does not SFINAE out
// when the trailing return-type is invalid but keep the
// trailing return-type when it is valid
struct get_completion_signatures_sfinae {
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
auto operator()(_Self&& __self, _Env&&... __env) const
-> decltype(__self.__tag().get_completion_signatures(
static_cast<_Self&&>(__self),
static_cast<_Env&&>(__env)...)) {
return {};
}
};
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
requires(stdexec::__is_debug_env<_Env> || ... || false)
|| (!stdexec::__callable<get_completion_signatures_sfinae, _Self, _Env...>)
static auto get_completion_signatures(_Self&& __self, _Env&&... __env) {
return __self.__tag()
.get_completion_signatures(static_cast<_Self&&>(__self), static_cast<_Env&&>(__env)...);
}
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
requires(!stdexec::__is_debug_env<_Env> && ... && true)
static auto get_completion_signatures(_Self&& __self, _Env&&... __env)
-> decltype(__self.__tag().get_completion_signatures(
static_cast<_Self&&>(__self),
static_cast<_Env&&>(__env)...)) {
return {};
}
// make sure that get_item_types does not SFINAE out
// when the trailing return-type is invalid but keep the
// trailing return-type when it is valid
struct get_item_types_sfinae {
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
auto
operator()(_Self&& __self, _Env&&... __env) const -> decltype(__self.__tag().get_item_types(
static_cast<_Self&&>(__self),
static_cast<_Env&&>(__env)...)) {
return {};
}
};
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
requires(stdexec::__is_debug_env<_Env> || ... || false)
|| (!stdexec::__callable<get_item_types_sfinae, _Self, _Env...>)
static auto get_item_types(_Self&& __self, _Env&&... __env) {
return __self.__tag()
.get_item_types(static_cast<_Self&&>(__self), static_cast<_Env&&>(__env)...);
}
template <stdexec::__decays_to<__seqexpr> _Self, class... _Env>
requires(!stdexec::__is_debug_env<_Env> && ... && true)
static auto get_item_types(_Self&& __self, _Env&&... __env)
-> decltype(__self.__tag()
.get_item_types(static_cast<_Self&&>(__self), static_cast<_Env&&>(__env)...)) {
return {};
}
// make sure that subscribe does not SFINAE out
// when the trailing return-type is invalid but keep the
// trailing return-type when it is valid
struct subscribe_sfinae {
template <stdexec::__decays_to<__seqexpr> _Self, stdexec::receiver _Receiver>
auto operator()(_Self&& __self, _Receiver&& __rcvr) const noexcept(noexcept(
__self.__tag().subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr))))
-> decltype(__self.__tag()
.subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr))) {
return __tag_t::subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr));
}
};
template <stdexec::__decays_to<__seqexpr> _Self, stdexec::receiver _Receiver>
requires stdexec::__is_debug_env<stdexec::env_of_t<_Receiver>>
|| (!stdexec::__callable<subscribe_sfinae, _Self, _Receiver>)
static auto subscribe(_Self&& __self, _Receiver&& __rcvr) noexcept(noexcept(
__self.__tag().subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr)))) {
return __tag_t::subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr));
}
template <stdexec::__decays_to<__seqexpr> _Self, stdexec::receiver _Receiver>
requires(!stdexec::__is_debug_env<stdexec::env_of_t<_Receiver>>)
static auto subscribe(_Self&& __self, _Receiver&& __rcvr) noexcept(noexcept(
__self.__tag().subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr))))
-> decltype(__self.__tag()
.subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr))) {
return __tag_t::subscribe(static_cast<_Self&&>(__self), static_cast<_Receiver&&>(__rcvr));
}
template <class _Sequence, class _ApplyFn>
static auto apply(_Sequence&& __sequence, _ApplyFn&& __fun)
noexcept(stdexec::__nothrow_callable<
stdexec::__detail::__impl_of<_Sequence>,
stdexec::__copy_cvref_fn<_Sequence>,
_ApplyFn
>)
-> stdexec::__call_result_t<
stdexec::__detail::__impl_of<_Sequence>,
stdexec::__copy_cvref_fn<_Sequence>,
_ApplyFn
> {
return static_cast<_Sequence&&>(__sequence)
.__impl_(stdexec::__copy_cvref_fn<_Sequence>(), static_cast<_ApplyFn&&>(__fun));
}
};
template <class _Tag, class _Data, class... _Child>
STDEXEC_ATTRIBUTE(host, device)
__seqexpr(_Tag, _Data, _Child...) -> __seqexpr<STDEXEC_SEXPR_DESCRIPTOR(_Tag, _Data, _Child...)>;
template <class _Tag, class _Data, class... _Child>
using __seqexpr_t = __seqexpr<STDEXEC_SEXPR_DESCRIPTOR(_Tag, _Data, _Child...)>;
namespace __mkseqexpr {
template <class _Tag, class _Domain = stdexec::default_domain>
struct make_sequence_expr_t {
template <class _Data = stdexec::__, class... _Children>
constexpr auto operator()(_Data __data = {}, _Children... __children) const {
return __seqexpr_t<_Tag, _Data, _Children...>{
_Tag(), static_cast<_Data&&>(__data), static_cast<_Children&&>(__children)...};
}
};
} // namespace __mkseqexpr
struct __basic_sequence_sender_name {
template <class _Tag, class _Data, class... _Child>
using __result = __basic_sequence_sender<_Tag, _Data, stdexec::__name_of<_Child>...>;
template <class _Sender>
using __f =
stdexec::__minvoke<typename stdexec::__decay_t<_Sender>::__desc_t, stdexec::__q<__result>>;
};
template <class _Tag, class _Domain = stdexec::default_domain>
inline constexpr __mkseqexpr::make_sequence_expr_t<_Tag, _Domain> make_sequence_expr{};
} // namespace exec
namespace stdexec::__detail {
template <auto _DescriptorFn>
extern exec::__basic_sequence_sender_name __name_of_v<exec::__seqexpr<_DescriptorFn>>;
} // namespace stdexec::__detail