@@ -38,6 +38,21 @@ extern std::atomic<intptr_t> g_resumef_task_count; | |||
extern std::atomic<intptr_t> g_resumef_evtctx_count; | |||
#endif | |||
namespace std | |||
{ | |||
#if !_HAS_CXX20 | |||
template<class T> | |||
struct remove_cvref | |||
{ | |||
typedef std::remove_cv_t<std::remove_reference_t<T>> type; | |||
}; | |||
#if _HAS_CXX17 | |||
template<class T> | |||
using remove_cvref_t = typename std::remove_cvref<T>::type; | |||
#endif | |||
#endif | |||
} | |||
namespace resumef | |||
{ | |||
#if _HAS_CXX17 | |||
@@ -47,6 +62,7 @@ namespace resumef | |||
template<class... _Mutexes> | |||
using scoped_lock = std::lock_guard<_Mutexes...>; | |||
#endif | |||
template<typename _PromiseT = void> | |||
using coroutine_handle = std::experimental::coroutine_handle<_PromiseT>; | |||
@@ -149,9 +149,9 @@ namespace resumef | |||
//这个'函数对象'被调用后,返回generator<_Ty>/future_t<_Ty>类型 | |||
//然后'函数对象'作为异步执行的上下文状态保存起来 | |||
template<class _Ctx> | |||
struct ctx_task_t : public task_t<typename std::decay<decltype(std::declval<_Ctx>()())>::type> | |||
struct ctx_task_t : public task_t<typename std::remove_cvref<decltype(std::declval<_Ctx>()())>::type> | |||
{ | |||
typedef task_t<typename std::decay<decltype(std::declval<_Ctx>()())>::type> base_type; | |||
typedef task_t<typename std::remove_cvref<decltype(std::declval<_Ctx>()())>::type> base_type; | |||
using base_type::_future; | |||
typedef _Ctx context_type; |
@@ -82,7 +82,7 @@ __declspec(noinline) | |||
auto tostring_async(_Input_t&& value, _Callable_t&& token) | |||
{ | |||
//适配器类型 | |||
using _Adapter_t = modern_callback_adapter_t<std::decay_t<_Callable_t>, void(std::string)>; | |||
using _Adapter_t = modern_callback_adapter_t<typename std::remove_cvref<_Callable_t>::type, void(std::string)>; | |||
//通过适配器获得兼容_Signature_t类型的真正的回调,以及返回值_Return_t | |||
auto adapter = typename _Adapter_t::traits(std::forward<_Callable_t>(token)); | |||
@@ -100,7 +100,7 @@ auto tostring_async(_Input_t&& value, _Callable_t&& token) | |||
//或者宏版本写法 | |||
#define MODERN_CALLBACK_TRAITS(_Token_value, _Signature_t) \ | |||
using _Adapter_t = modern_callback_adapter_t<std::decay_t<_Callable_t>, _Signature_t>; \ | |||
using _Adapter_t = modern_callback_adapter_t<typename std::remove_cvref<_Callable_t>::type, _Signature_t>; \ | |||
auto _Adapter_value = typename _Adapter_t::traits(std::forward<_Callable_t>(_Token_value)) | |||
#define MODERN_CALLBACK_CALL() std::move(std::get<0>(_Adapter_value)) | |||
#define MODERN_CALLBACK_RETURN() return std::move(std::get<1>(_Adapter_value)).get() |