From 71d373ae820706da28b3cb75bfaf0cdce0df0341 Mon Sep 17 00:00:00 2001 From: tearshark Date: Sun, 15 Mar 2020 23:22:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=5FWhenTaskT=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- librf/librf.h | 6 +++--- librf/src/type_concept.inl | 27 +++++++++++++++++++-------- vs_proj/librf.vcxproj | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/librf/librf.h b/librf/librf.h index 8723325..0ec882a 100644 --- a/librf/librf.h +++ b/librf/librf.h @@ -60,12 +60,12 @@ #include "src/switch_scheduler.h" #include "src/current_scheduler.h" +#include "src/sleep.h" +#include "src/when.h" + #include "src/_awaker.h" #include "src/mutex.h" #include "src/ring_queue.h" #include "src/intrusive_link_queue.h" #include "src/channel.h" #include "src/event.h" - -#include "src/sleep.h" -#include "src/when.h" diff --git a/librf/src/type_concept.inl b/librf/src/type_concept.inl index 0c7ae64..6057dfb 100644 --- a/librf/src/type_concept.inl +++ b/librf/src/type_concept.inl @@ -1,8 +1,12 @@ #pragma once #ifndef RESUMEF_ENABLE_CONCEPT -#define RESUMEF_ENABLE_CONCEPT 0 -#endif +#ifdef __cpp_lib_concepts +#define RESUMEF_ENABLE_CONCEPT 1 +#else +#define RESUMEF_ENABLE_CONCEPT 1 +#endif //#ifdef __cpp_lib_concepts +#endif //#ifndef RESUMEF_ENABLE_CONCEPT #if RESUMEF_ENABLE_CONCEPT #include @@ -14,7 +18,7 @@ RESUMEF_NS #if RESUMEF_ENABLE_CONCEPT template - concept _AwaitorT = requires(T && v) + concept _AwaitorT = requires(T&& v) { { v.await_ready() } -> bool; { v.await_suspend(std::declval>>()) }; @@ -22,7 +26,7 @@ RESUMEF_NS }; template - concept _HasStateT = requires(T && v) + concept _HasStateT = requires(T&& v) { { v._state }; { traits::is_state_pointer_v != false }; @@ -43,10 +47,16 @@ RESUMEF_NS concept _GeneratorT = std::is_same_v>; template - concept _WhenTaskT = _AwaitorT || _CallableT; + concept _AwaitableT = requires(T&& v) + { + { traits::get_awaitor(v) }; + }; template - concept _IteratorT = requires(T && u, T && v) + concept _WhenTaskT = _AwaitableT || _CallableT; + + template + concept _IteratorT = requires(T&& u, T&& v) { { ++u }->T; { u != v } -> bool; @@ -54,13 +64,13 @@ RESUMEF_NS }; template - concept _WhenIterT = _IteratorT && requires(T&& u, T&& v) + concept _WhenIterT = _IteratorT && requires(T&& u) { requires _WhenTaskT; }; template - concept _ContainerT = requires(T && v) + concept _ContainerT = requires(T&& v) { { std::begin(v) }; { std::end(v) }; @@ -80,6 +90,7 @@ RESUMEF_NS #define _FutureT typename #define _CallableT typename #define _GeneratorT typename +#define _AwaitableT typename #define _WhenTaskT typename #define _IteratorT typename #define _WhenIterT typename diff --git a/vs_proj/librf.vcxproj b/vs_proj/librf.vcxproj index 8dbc73e..3f02bbe 100644 --- a/vs_proj/librf.vcxproj +++ b/vs_proj/librf.vcxproj @@ -40,7 +40,7 @@ Application - ClangCL + v142 true