Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/hello_coro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@
#include <stdexec/execution.hpp>

#if !STDEXEC_NO_STDCPP_COROUTINES() && !STDEXEC_NVHPC()
# include <exec/task.hpp>

using namespace stdexec;

template <sender S1, sender S2>
auto async_answer(S1 s1, S2 s2) -> exec::task<int>
auto async_answer(S1 s1, S2 s2) -> stdexec::task<int>
{
// Senders are implicitly awaitable (in this coroutine type):
co_await static_cast<S2&&>(s2);
co_return co_await static_cast<S1&&>(s1);
}

template <sender S1, sender S2>
auto async_answer2(S1 s1, S2 s2) -> exec::task<std::optional<int>>
auto async_answer2(S1 s1, S2 s2) -> stdexec::task<std::optional<int>>
{
co_return co_await stopped_as_optional(async_answer(s1, s2));
}

// tasks have an associated stop token
auto async_stop_token() -> exec::task<std::optional<stdexec::inplace_stop_token>>
auto async_stop_token() -> stdexec::task<std::optional<stdexec::inplace_stop_token>>
{
co_return co_await stopped_as_optional(get_stop_token());
}
Expand Down
10 changes: 4 additions & 6 deletions include/exec/any_sender_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,8 @@ namespace experimental::execution

void __reset() noexcept
{
(*__vtable_)(__any::__delete, this);
__object_pointer_ = nullptr;
__vtable_ = __default_storage_vtable(static_cast<__vtable_t*>(nullptr));
auto* __default_vtable = __default_storage_vtable((__vtable_t*) nullptr);
(*std::exchange(__vtable_, __default_vtable))(__any::__delete, this);
}

[[nodiscard]]
Expand Down Expand Up @@ -561,9 +560,8 @@ namespace experimental::execution

void __reset() noexcept
{
(*__vtable_)(__any::__delete, this);
__object_pointer_ = nullptr;
__vtable_ = __default_storage_vtable(static_cast<__vtable_t*>(nullptr));
auto* __default_vtable = __default_storage_vtable((__vtable_t*) nullptr);
(*std::exchange(__vtable_, __default_vtable))(__any::__delete, this);
}

auto __get_vtable() const noexcept -> _Vtable const *
Expand Down
2 changes: 1 addition & 1 deletion include/exec/at_coroutine_exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace experimental::execution
{
auto __cont = __h.promise().continuation();
auto __coro = __h.promise().__is_stopped_ ? __cont.unhandled_stopped() : __cont.handle();
return STDEXEC_DESTROY_AND_CONTINUE(__h, __coro);
return STDEXEC_CORO_DESTROY_AND_CONTINUE(__h, __coro);
}

void await_resume() const noexcept {}
Expand Down
2 changes: 1 addition & 1 deletion include/exec/on_coro_disposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace experimental::execution
{
auto __cont = __h.promise().continuation();
auto __coro = __h.promise().__is_stopped_ ? __cont.unhandled_stopped() : __cont.handle();
return STDEXEC_DESTROY_AND_CONTINUE(__h, __coro);
return STDEXEC_CORO_DESTROY_AND_CONTINUE(__h, __coro);
}

void await_resume() const noexcept {}
Expand Down
30 changes: 17 additions & 13 deletions include/stdexec/__detail/__awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#pragma once

#include "../functional.hpp"
#include "__concepts.hpp"
#include "__config.hpp"
#include "__meta.hpp"
Expand All @@ -39,20 +40,20 @@ namespace STDEXEC
__promise.await_transform(static_cast<_Awaitable &&>(__awaitable));
};

template <class _Awaitable>
constexpr auto __get_awaitable(_Awaitable &&__awaitable, __ignore = {}) -> decltype(auto)
{
return static_cast<_Awaitable &&>(__awaitable);
}
inline constexpr auto __get_awaitable = __first_callable{
[]<class _Promise, __has_await_transform<_Promise> _Awaitable>(_Awaitable &&__awaitable,
_Promise &__promise)
-> decltype(auto)
{ return __promise.await_transform(static_cast<_Awaitable &&>(__awaitable)); },
[]<class _Awaitable>(_Awaitable &&__awaitable, __ignore = {}) -> decltype(auto)
{ return static_cast<_Awaitable &&>(__awaitable); }};

template <class _Promise, __has_await_transform<_Promise> _Awaitable>
constexpr auto __get_awaitable(_Awaitable &&__awaitable, _Promise &__promise) -> decltype(auto)
{
return __promise.await_transform(static_cast<_Awaitable &&>(__awaitable));
}
template <class _Awaitable, class _Promise>
using __awaitable_of_t = decltype(STDEXEC::__get_awaitable(__declval<_Awaitable>(),
__declval<_Promise &>()));

template <class _Awaitable>
constexpr auto __get_awaiter(_Awaitable &&__awaitable) -> decltype(auto)
inline constexpr auto __get_awaiter =
[]<class _Awaitable>(_Awaitable &&__awaitable) -> decltype(auto)
{
if constexpr (requires { __declval<_Awaitable>().operator co_await(); })
{
Expand All @@ -66,7 +67,10 @@ namespace STDEXEC
{
return static_cast<_Awaitable &&>(__awaitable);
}
}
};

template <class _Awaitable>
using __awaiter_of_t = decltype(STDEXEC::__get_awaiter(__declval<_Awaitable>()));

template <class _Awaitable, class... _Promise>
concept __awaitable = requires(_Awaitable &&__awaitable, _Promise &...__promise) {
Expand Down
9 changes: 9 additions & 0 deletions include/stdexec/__detail/__config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ namespace STDEXEC::__std
# define STDEXEC_PRAGMA_IGNORE_MSVC(...)
#endif

#if STDEXEC_MSVC()
# define STDEXEC_PRAGMA_OPTIMIZE_BEGIN() STDEXEC_PRAGMA(optimize("", on))
# define STDEXEC_PRAGMA_OPTIMIZE_END() STDEXEC_PRAGMA(optimize("", off))
#else
# define STDEXEC_PRAGMA_OPTIMIZE_BEGIN() STDEXEC_PRAGMA(GCC push_options) \
STDEXEC_PRAGMA(GCC optimize("O3"))
# define STDEXEC_PRAGMA_OPTIMIZE_END() STDEXEC_PRAGMA(GCC pop_options)
#endif

#if !STDEXEC_MSVC() && defined(__has_builtin)
# define STDEXEC_HAS_BUILTIN __has_builtin
#else
Expand Down
2 changes: 1 addition & 1 deletion include/stdexec/__detail/__connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace STDEXEC
};

template <class _Sender, class _Receiver>
concept __with_co_await = __awaitable<_Sender, __connect_await::__promise<_Receiver>>;
concept __with_co_await = __awaitable<_Sender, __connect_await::__promise<_Sender, _Receiver>>;

template <class _Sender, class _Receiver>
concept __with_legacy_tag_invoke = __tag_invocable<connect_t, _Sender, _Receiver>;
Expand Down
Loading
Loading