@@ -1,5 +1,7 @@ | |||
#pragma once | |||
#define RESUMEF_LIB_INCLUDE 1 | |||
//#include <yvals.h> | |||
#include <atomic> | |||
#include <memory> |
@@ -162,6 +162,11 @@ namespace resumef | |||
{ | |||
_future = std::move(_context()); | |||
} | |||
ctx_task_t(const context_type & ctx) | |||
: _context(ctx) | |||
{ | |||
_future = std::move(_context()); | |||
} | |||
}; | |||
} |
@@ -38,7 +38,7 @@ namespace resumef | |||
inline void operator + (_Ty && t_) | |||
{ | |||
typedef typename std::conditional< | |||
std::is_callable_v<_Ty>, | |||
std::is_callable<_Ty>::value, | |||
ctx_task_t<_Ty>, | |||
task_t<_Ty> >::type task_type; | |||
return new_task(new task_type(std::forward<_Ty>(t_))); |
@@ -61,9 +61,9 @@ namespace resumef | |||
public: | |||
timer_handler() = default; | |||
timer_handler(const timer_handler &) = default; | |||
timer_handler(timer_handler && right_); | |||
timer_handler(timer_handler && right_) noexcept; | |||
timer_handler & operator = (const timer_handler &) = default; | |||
timer_handler & operator = (timer_handler && right_); | |||
timer_handler & operator = (timer_handler && right_) noexcept; | |||
timer_handler(timer_manager * manager_, const detail::timer_target_ptr & target_); | |||
@@ -141,13 +141,13 @@ namespace resumef | |||
, _target(target_) | |||
{ | |||
} | |||
inline timer_handler::timer_handler(timer_handler && right_) | |||
inline timer_handler::timer_handler(timer_handler && right_) noexcept | |||
: _manager(std::move(right_._manager)) | |||
, _target(std::move(right_._target)) | |||
{ | |||
} | |||
inline timer_handler & timer_handler::operator = (timer_handler && right_) | |||
inline timer_handler & timer_handler::operator = (timer_handler && right_) noexcept | |||
{ | |||
if (this != &right_) | |||
{ |
@@ -3,13 +3,13 @@ | |||
namespace std | |||
{ | |||
template<typename _Function> | |||
inline auto _IsCallable(const _Function & _Func, int) -> decltype(_Func(), true_type()) | |||
inline auto _IsCallable(_Function && _Func, int) -> decltype(_Func(), true_type()) | |||
{ | |||
(_Func); | |||
return true_type(); | |||
} | |||
template<typename _Function> | |||
inline false_type _IsCallable(const _Function &, ...) | |||
inline false_type _IsCallable(_Function &&, ...) | |||
{ | |||
return false_type(); | |||
} | |||
@@ -17,7 +17,8 @@ namespace std | |||
template<typename _Function> | |||
using is_callable = decltype(_IsCallable(std::declval<_Function>(), 0)); | |||
#if _HAS_CXX17 | |||
template<typename _Function> | |||
_INLINE_VAR constexpr bool is_callable_v = is_callable<_Function>::value; | |||
#endif | |||
} | |||
@@ -88,22 +88,22 @@ void test_when_all() | |||
GO | |||
{ | |||
co_await when_all(); | |||
std::cout << "zero!" << std::endl << std::endl; | |||
std::cout << "when all: zero!" << std::endl << std::endl; | |||
auto [a, b] = co_await when_all(my_sleep("a"), my_sleep_v("b")); | |||
b; //b is std::ignore | |||
std::cout << a << std::endl << std::endl; | |||
(void)b; //b is std::ignore | |||
std::cout << "when all:" << a << std::endl << std::endl; | |||
auto c = co_await my_sleep("c"); | |||
std::cout << c << std::endl << std::endl; | |||
std::cout << "when all:" << c << std::endl << std::endl; | |||
auto [d, e, f] = co_await when_all(my_sleep("d"), my_sleep_v("e"), my_sleep("f")); | |||
e; //e is std::ignore | |||
std::cout << d << "," << f << std::endl << std::endl; | |||
(void)e; //e is std::ignore | |||
std::cout << "when all:" << d << "," << f << std::endl << std::endl; | |||
std::vector<future_t<int> > v{ my_sleep("g"), my_sleep("h"), my_sleep("i") }; | |||
auto vals = co_await when_all(std::begin(v), std::end(v)); | |||
std::cout << vals[0] << "," << vals[1] << "," << vals[2] << "," << std::endl << std::endl; | |||
std::cout << "when all:" << vals[0] << "," << vals[1] << "," << vals[2] << "," << std::endl << std::endl; | |||
std::cout << "all range done!" << std::endl; | |||
}; |
@@ -43,9 +43,6 @@ auto test_yield_void() | |||
} | |||
*/ | |||
#define co_yield_void co_yield nullptr | |||
#define co_return_void co_return nullptr | |||
auto test_yield_void() | |||
{ | |||
std::cout << "block 1 will yield return" << std::endl; |
@@ -22,9 +22,9 @@ extern void resumable_main_benchmark_mem(); | |||
int main(int argc, const char * argv[]) | |||
{ | |||
resumable_main_sleep(); | |||
//resumable_main_sleep(); | |||
//resumable_main_resumable(); | |||
/* | |||
resumable_main_when_all(); | |||
resumable_main_multi_thread(); | |||
resumable_main_yield_return(); | |||
@@ -40,7 +40,6 @@ int main(int argc, const char * argv[]) | |||
resumable_main_channel(); | |||
resumable_main_cb(); | |||
resumable_main_exception(); | |||
*/ | |||
return 0; | |||
} |