Skip to content

Commit

Permalink
Chore: improve concept definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
willkill07 committed Dec 3, 2024
1 parent 10439b3 commit 6704705
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cpp/mrc/include/mrc/core/concepts/not_void.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
namespace mrc::core::concepts {

template <typename T>
concept not_void = requires { requires not std::same_as<T, void>; };
concept not_void = (not std::same_as<T, void>);

} // namespace mrc::core::concepts
19 changes: 11 additions & 8 deletions cpp/mrc/include/mrc/coroutines/concepts/awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
#include <utility>

namespace mrc::coroutines::concepts {

// clang-format off
/**
* The concept declares a type that is required to be one of the passed types
*/
template<typename T, typename ... CandidatesT>
concept one_of = (... or std::same_as<T, CandidatesT>);

/**
* This concept declares a type that is required to meet the c++20 coroutine operator co_await()
* retun type. It requires the following three member functions:
Expand All @@ -52,14 +60,11 @@ namespace mrc::coroutines::concepts {
* await_resume() -> decltype(auto)
* Where the return type on await_resume is the requested return of the awaitable.
*/
// clang-format off
template<typename T>
concept awaiter = requires(T t, std::coroutine_handle<> c)
{
{ t.await_ready() } -> std::same_as<bool>;
requires std::same_as<decltype(t.await_suspend(c)), void> ||
std::same_as<decltype(t.await_suspend(c)), bool> ||
std::same_as<decltype(t.await_suspend(c)), std::coroutine_handle<>>;
{ t.await_suspend(c) } -> one_of<void, bool, std::coroutine_handle<>>;
{ t.await_resume() };
};

Expand All @@ -77,10 +82,8 @@ template<typename T>
concept awaiter_void = requires(T t, std::coroutine_handle<> c)
{
{ t.await_ready() } -> std::same_as<bool>;
requires std::same_as<decltype(t.await_suspend(c)), void> ||
std::same_as<decltype(t.await_suspend(c)), bool> ||
std::same_as<decltype(t.await_suspend(c)), std::coroutine_handle<>>;
{t.await_resume()} -> std::same_as<void>;
{ t.await_suspend(c) } -> one_of<void, bool, std::coroutine_handle<>>;
{ t.await_resume() } -> std::same_as<void>;
};

template<typename T>
Expand Down

0 comments on commit 6704705

Please sign in to comment.