Skip to content

Commit 2e87822

Browse files
authored
Merge pull request NVIDIA#1459 from NVIDIA/misc-tweaks
use `__is_function` intrinsic in `__invoke` implementation
2 parents 5fe7bdb + d05c62e commit 2e87822

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

include/stdexec/__detail/__config.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ namespace __coro = std::experimental;
339339
# define STDEXEC_IS_CONST(...) stdexec::__is_const_<__VA_ARGS__>
340340
#endif
341341

342+
#if STDEXEC_HAS_BUILTIN(__is_function)
343+
# define STDEXEC_IS_FUNCTION(...) __is_function(__VA_ARGS__)
344+
#else
345+
# define STDEXEC_IS_FUNCTION(...) \
346+
(!STDEXEC_IS_CONST(__VA_ARGS__) && !STDEXEC_IS_CONST(const __VA_ARGS__))
347+
#endif
348+
342349
#if STDEXEC_HAS_BUILTIN(__is_same)
343350
# define STDEXEC_IS_SAME(...) __is_same(__VA_ARGS__)
344351
#elif STDEXEC_HAS_BUILTIN(__is_same_as)

include/stdexec/functional.hpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,45 @@ namespace stdexec {
123123

124124
template <class _Mbr, class _Class, class _Ty>
125125
auto __invoke_selector(_Mbr _Class::*, const _Ty&) noexcept {
126-
if constexpr (STDEXEC_IS_CONST(_Mbr) || STDEXEC_IS_CONST(_Mbr const)) {
126+
if constexpr (STDEXEC_IS_FUNCTION(_Mbr)) {
127127
// member function ptr case
128128
if constexpr (STDEXEC_IS_BASE_OF(_Class, _Ty)) {
129-
return __memobj{};
129+
return __memfn{};
130130
} else if constexpr (__is_refwrap<_Ty>) {
131-
return __memobj_refwrap{};
131+
return __memfn_refwrap{};
132132
} else {
133-
return __memobj_smartptr{};
133+
return __memfn_smartptr{};
134134
}
135135
} else {
136136
// member object ptr case
137137
if constexpr (STDEXEC_IS_BASE_OF(_Class, _Ty)) {
138-
return __memfn{};
138+
return __memobj{};
139139
} else if constexpr (__is_refwrap<_Ty>) {
140-
return __memfn_refwrap{};
140+
return __memobj_refwrap{};
141141
} else {
142-
return __memfn_smartptr{};
142+
return __memobj_smartptr{};
143143
}
144144
}
145145
}
146146

147147
struct __invoke_t {
148148
template <class _Fun>
149-
STDEXEC_ATTRIBUTE((always_inline)) constexpr auto
150-
operator()(_Fun&& __fun) const noexcept(noexcept((static_cast<_Fun&&>(__fun))()))
151-
-> decltype((static_cast<_Fun&&>(__fun))()) {
149+
STDEXEC_ATTRIBUTE((always_inline)) constexpr auto operator()(_Fun&& __fun) const
150+
noexcept(noexcept(static_cast<_Fun&&>(__fun)())) -> decltype(static_cast<_Fun&&>(__fun)()) {
152151
return static_cast<_Fun&&>(__fun)();
153152
}
154153

155154
template <class _Fun, class _Ty, class... _Args>
156-
STDEXEC_ATTRIBUTE((always_inline)) constexpr auto operator()(_Fun&& __fun, _Ty&& __ty, _Args&&... __args) const
157-
noexcept(noexcept(__invoke_selector(__fun, __ty)(
155+
STDEXEC_ATTRIBUTE((always_inline)) constexpr auto operator()(_Fun&& __fun, _Ty&& __ty, _Args&&... __args) const
156+
noexcept(noexcept(__invoke_::__invoke_selector(__fun, __ty)(
158157
static_cast<_Fun&&>(__fun),
159158
static_cast<_Ty&&>(__ty),
160159
static_cast<_Args&&>(__args)...)))
161-
-> decltype(__invoke_selector(__fun, __ty)(
160+
-> decltype(__invoke_::__invoke_selector(__fun, __ty)(
162161
static_cast<_Fun&&>(__fun),
163162
static_cast<_Ty&&>(__ty),
164163
static_cast<_Args&&>(__args)...)) {
165-
return decltype(__invoke_selector(__fun, __ty))()(
164+
return decltype(__invoke_::__invoke_selector(__fun, __ty))()(
166165
static_cast<_Fun&&>(__fun), static_cast<_Ty&&>(__ty), static_cast<_Args&&>(__args)...);
167166
}
168167
};
@@ -230,25 +229,4 @@ namespace stdexec {
230229
};
231230

232231
inline constexpr __apply_t __apply{};
233-
234-
template <class _Tag, class _Ty>
235-
struct __field {
236-
STDEXEC_ATTRIBUTE((always_inline)) _Ty operator()(_Tag) const noexcept(__nothrow_decay_copyable<const _Ty&>) {
237-
return __t_;
238-
}
239-
240-
_Ty __t_;
241-
};
242-
243-
template <class _Tag>
244-
struct __mkfield_ {
245-
template <class _Ty>
246-
STDEXEC_ATTRIBUTE((always_inline)) __field<_Tag, __decay_t<_Ty>>
247-
operator()(_Ty&& __ty) const noexcept(__nothrow_decay_copyable<_Ty>) {
248-
return {static_cast<_Ty&&>(__ty)};
249-
}
250-
};
251-
252-
template <class _Tag>
253-
inline constexpr __mkfield_<_Tag> __mkfield{};
254232
} // namespace stdexec

0 commit comments

Comments
 (0)