diff --git a/async_simple/uthread/Async.h b/async_simple/uthread/Async.h index 56e8fcc0b..0b8089033 100644 --- a/async_simple/uthread/Async.h +++ b/async_simple/uthread/Async.h @@ -41,23 +41,19 @@ namespace async_simple { namespace uthread { -struct Launch { - struct Prompt {}; - struct Schedule {}; - struct Current {}; +enum class Launch { + Prompt, + Schedule, + Current, }; -template ::value, - T>::type* = nullptr> -inline Uthread async(F&& f, Executor* ex) { +template +requires(policy == Launch::Prompt) inline Uthread async(F&& f, Executor* ex) { return Uthread(Attribute{ex}, std::forward(f)); } -template ::value, - T>::type* = nullptr> -inline void async(F&& f, Executor* ex) { +template +requires(policy == Launch::Schedule) inline void async(F&& f, Executor* ex) { if (!ex) AS_UNLIKELY { return; } ex->schedule([f = std::move(f), ex]() { @@ -67,10 +63,9 @@ inline void async(F&& f, Executor* ex) { } // schedule async task, set a callback -template ::value, - T>::type* = nullptr> -inline void async(F&& f, C&& c, Executor* ex) { +template +requires(policy == Launch::Schedule) inline void async(F&& f, C&& c, + Executor* ex) { if (!ex) AS_UNLIKELY { return; } ex->schedule([f = std::move(f), c = std::move(c), ex]() { @@ -79,10 +74,8 @@ inline void async(F&& f, C&& c, Executor* ex) { }); } -template ::value, - T>::type* = nullptr> -inline void async(F&& f, Executor* ex) { +template +requires(policy == Launch::Current) inline void async(F&& f, Executor* ex) { Uthread uth(Attribute{ex}, std::forward(f)); uth.detach(); } diff --git a/async_simple/uthread/Collect.h b/async_simple/uthread/Collect.h index 0edcfcf5a..e39e25132 100644 --- a/async_simple/uthread/Collect.h +++ b/async_simple/uthread/Collect.h @@ -50,7 +50,7 @@ namespace uthread { // TODO: Due to it is possible that the user of async_simple doesn't support // c++17, we didn't merge this two implementation by if constexpr. Merge them // once the codebases are ready to use c++17. -template +template std::vector::value_type>>::value, @@ -58,7 +58,7 @@ std::vector collectAll(Iterator first, Iterator last, Executor* ex) { assert(std::distance(first, last) >= 0); - static_assert(!std::is_same::value, + static_assert(Policy != Launch::Prompt, "collectAll not support Prompt launch policy"); using ResultType = std::invoke_result_t< @@ -93,14 +93,14 @@ collectAll(Iterator first, Iterator last, Executor* ex) { }); } -template +template typename std::enable_if< std::is_void::value_type>>::value, void>::type collectAll(Iterator first, Iterator last, Executor* ex) { assert(std::distance(first, last) >= 0); - static_assert(!std::is_same::value, + static_assert(Launch::Prompt != Policy, "collectN not support Prompt launch policy"); struct Context {