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
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
"loadu",
"cvtps",
"neww",
"STDCORO"
"STDCORO",
"NOMINMAX"
],
"flagWords": [
"hte"
Expand Down
1 change: 1 addition & 0 deletions include/dpp/coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
#include "coro/coroutine.h"
#include "coro/job.h"
#include "coro/task.h"
#include "coro/when_any.h"

#endif /* DPP_CORO */
7 changes: 7 additions & 0 deletions include/dpp/coro/coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ requires (!has_co_await_member<T> && !has_free_co_await<T>)
decltype(auto) co_await_resolve(T&& expr) noexcept {
return static_cast<T&&>(expr);
}

#else
/**
* @brief Concept to check if a type has a useable `operator co_await()` member
Expand Down Expand Up @@ -145,6 +146,12 @@ bool has_await_members;
decltype(auto) co_await_resolve(auto&& expr) {}
#endif

/**
* @brief Convenience alias for the result of a certain awaitable's await_resume.
*/
template <typename T>
using awaitable_result = decltype(co_await_resolve(std::declval<T>()).await_resume());

} // namespace detail

struct confirmation_callback_t;
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/coro/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ namespace detail {

/**
* @brief Second function called by the standard library when reaching the end of a coroutine.
*
*
* @return std::coroutine_handle<> Coroutine handle to resume, this is either the parent if present or std::noop_coroutine()
*/
std_coroutine::coroutine_handle<> await_suspend(std_coroutine::coroutine_handle<coroutine_promise<R>> handle) const noexcept {
Expand Down
9 changes: 6 additions & 3 deletions include/dpp/coro/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ struct job {};
namespace detail {

template <typename... Args>
inline constexpr bool coroutine_has_ref_params_v = (std::is_reference_v<Args> || ... || false);
inline constexpr bool coroutine_has_no_ref_params_v = false;

template <>
inline constexpr bool coroutine_has_no_ref_params_v<> = true;

template <typename T, typename... Args>
inline constexpr bool coroutine_has_ref_params_v<T, Args...> = (std::is_reference_v<Args> || ... || (std::is_reference_v<T> && !std::is_invocable_v<T, Args...>));
inline constexpr bool coroutine_has_no_ref_params_v<T, Args...> = (std::is_invocable_v<T, Args...> || !std::is_reference_v<T>) && (!std::is_reference_v<Args> && ... && true);

#ifdef DPP_CORO_TEST
struct job_promise_base{};
Expand Down Expand Up @@ -124,7 +127,7 @@ struct job_promise {
* If you must pass a reference, pass it as a pointer or with std::ref, but you must fully understand the reason behind this warning, and what to avoid.
* If you prefer a safer type, use `coroutine` for synchronous execution, or `task` for parallel tasks, and co_await them.
*/
static_assert(!coroutine_has_ref_params_v<Args...>, "co_await is disabled in dpp::job when taking parameters by reference. read comment above this line for more info");
static_assert(coroutine_has_no_ref_params_v<Args...>, "co_await is disabled in dpp::job when taking parameters by reference. read comment above this line for more info");

return std::forward<T>(expr);
}
Expand Down
Loading