@@ -109,7 +109,7 @@ RESUMEF_NS | |||
_counter.store(0, std::memory_order_release); | |||
counted_ptr<state_event_t> state; | |||
state_event_ptr state; | |||
for (; (state = try_pop_list(_wait_awakes)) != nullptr;) | |||
{ | |||
(void)state->on_notify(); | |||
@@ -120,7 +120,7 @@ RESUMEF_NS | |||
{ | |||
scoped_lock<lock_type> lock_(_lock); | |||
counted_ptr<state_event_t> state; | |||
state_event_ptr state; | |||
for (; (state = try_pop_list(_wait_awakes)) != nullptr;) | |||
{ | |||
if (state->on_notify()) |
@@ -40,10 +40,11 @@ RESUMEF_NS | |||
//而when_any会导致所有的event_t都被触发 | |||
//改日有空再补上 | |||
struct [[nodiscard]] any_awaiter; | |||
template<_IteratorT _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_v<_Iter> && std::is_same_v<event_t&, decltype(*std::declval<_Iter>())>) | |||
> | |||
template<class _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>) | |||
> RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>) | |||
static future_t<intptr_t> | |||
wait_any(_Iter begin_, _Iter end_) | |||
{ | |||
@@ -52,8 +53,8 @@ RESUMEF_NS | |||
} | |||
template<class _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_v<_Cont>) | |||
> | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>) | |||
> RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>) | |||
static future_t<intptr_t> | |||
wait_any(_Cont& cnt_) | |||
{ | |||
@@ -61,9 +62,9 @@ RESUMEF_NS | |||
co_return idx.first; | |||
} | |||
template<class _Rep, class _Period, _IteratorT _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_v<_Iter> && std::is_same_v<event_t&, decltype(*std::declval<_Iter>())>) | |||
> | |||
template<class _Rep, class _Period, class _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>) | |||
> RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>) | |||
static future_t<intptr_t> | |||
wait_any_for(const std::chrono::duration<_Rep, _Period>& dt, _Iter begin_, _Iter end_) | |||
{ | |||
@@ -74,9 +75,9 @@ RESUMEF_NS | |||
co_return idx.first; | |||
} | |||
template<class _Rep, class _Period, _ContainerT _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_v<_Cont>) | |||
> | |||
template<class _Rep, class _Period, class _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>) | |||
> RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>) | |||
static future_t<intptr_t> | |||
wait_any_for(const std::chrono::duration<_Rep, _Period>& dt, _Cont& cont) | |||
{ | |||
@@ -86,9 +87,9 @@ RESUMEF_NS | |||
template<_IteratorT _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_v<_Iter> && std::is_same_v<event_t&, decltype(*std::declval<_Iter>())>) | |||
> | |||
template<class _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>) | |||
> RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>) | |||
static future_t<bool> | |||
wait_all(_Iter begin_, _Iter end_) | |||
{ | |||
@@ -97,8 +98,8 @@ RESUMEF_NS | |||
} | |||
template<class _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_v<_Cont>) | |||
> | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>) | |||
> RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>) | |||
static future_t<bool> | |||
wait_all(_Cont& cnt_) | |||
{ | |||
@@ -106,9 +107,9 @@ RESUMEF_NS | |||
co_return is_all_succeeded(vb); | |||
} | |||
template<class _Rep, class _Period, _IteratorT _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_v<_Iter> && std::is_same_v<event_t&, decltype(*std::declval<_Iter>())>) | |||
> | |||
template<class _Rep, class _Period, class _Iter | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>) | |||
> RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>) | |||
static future_t<bool> | |||
wait_all_for(const std::chrono::duration<_Rep, _Period>& dt, _Iter begin_, _Iter end_) | |||
{ | |||
@@ -119,9 +120,9 @@ RESUMEF_NS | |||
co_return is_all_succeeded(vb); | |||
} | |||
template<class _Rep, class _Period, _ContainerT _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_v<_Cont>) | |||
> | |||
template<class _Rep, class _Period, class _Cont | |||
COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>) | |||
> RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>) | |||
static future_t<bool> | |||
wait_all_for(const std::chrono::duration<_Rep, _Period>& dt, _Cont& cont) | |||
{ |
@@ -29,7 +29,7 @@ RESUMEF_NS | |||
concept _HasStateT = requires(T&& v) | |||
{ | |||
{ v._state }; | |||
{ traits::is_state_pointer_v<decltype(v._state)> != false }; | |||
requires traits::is_state_pointer_v<decltype(v._state)>; | |||
}; | |||
template<typename T> | |||
@@ -59,10 +59,16 @@ RESUMEF_NS | |||
concept _IteratorT = requires(T&& u, T&& v) | |||
{ | |||
{ ++u }->T; | |||
{ u != v } -> bool; | |||
{ u != v } ->bool; | |||
{ *u }; | |||
}; | |||
template<typename T, typename E> | |||
concept _IteratorOfT = _IteratorT<T> && requires(T && u) | |||
{ | |||
{ *u } ->std::same_as<E&>; | |||
}; | |||
template<typename T> | |||
concept _WhenIterT = _IteratorT<T> && requires(T&& u) | |||
{ | |||
@@ -77,6 +83,12 @@ RESUMEF_NS | |||
requires std::same_as<decltype(std::begin(v)), decltype(std::end(v))>; | |||
}; | |||
template<typename T, typename E> | |||
concept _ContainerOfT = _ContainerT<T> && requires(T && u) | |||
{ | |||
{ *std::begin(u) } ->std::same_as<E&>; | |||
}; | |||
#define COMMA_RESUMEF_ENABLE_IF(...) | |||
#define RESUMEF_ENABLE_IF(...) | |||
#define RESUMEF_REQUIRES(...) requires __VA_ARGS__ | |||
@@ -91,8 +103,10 @@ RESUMEF_NS | |||
#define _AwaitableT typename | |||
#define _WhenTaskT typename | |||
#define _IteratorT typename | |||
#define _IteratorOfT typename | |||
#define _WhenIterT typename | |||
#define _ContainerT typename | |||
#define _ContainerOfT typename | |||
#define COMMA_RESUMEF_ENABLE_IF(...) ,typename=std::enable_if_t<__VA_ARGS__> | |||
#define RESUMEF_ENABLE_IF(...) typename=std::enable_if_t<__VA_ARGS__> |
@@ -58,9 +58,15 @@ RESUMEF_NS | |||
//is_iterator_v<T> | |||
//判断是不是一个支持向后迭代的迭代器 | |||
// | |||
//is_iterator_of_v<T, E> | |||
//判断是不是一个支持向后迭代的迭代器,并且迭代器通过 operator *()返回的类型是 E&。 | |||
// | |||
//is_container<T> | |||
//is_container_v<T> | |||
//判断是不是一个封闭区间的容器,或者数组。 | |||
// | |||
//is_container_of_v<T, E> | |||
//判断是不是一个封闭区间的容器,或者数组。其元素类型是E。 | |||
template<class _Ty> | |||
struct is_coroutine_handle : std::false_type {}; | |||
@@ -215,6 +221,11 @@ RESUMEF_NS | |||
: std::true_type{}; | |||
template<class _Ty> | |||
constexpr bool is_iterator_v = is_iterator<_Ty>::value; | |||
template<class _Ty, class _Ety> | |||
constexpr bool is_iterator_of_v = std::conjunction< | |||
is_iterator<_Ty> | |||
, std::is_same<_Ety&, decltype(*std::declval<_Ty>())> | |||
>::value; | |||
template<class _Ty, class = std::void_t<>> | |||
struct is_container : std::false_type {}; | |||
@@ -222,13 +233,11 @@ RESUMEF_NS | |||
struct is_container | |||
<_Ty, | |||
std::void_t< | |||
decltype(std::declval<_Ty>().begin()) | |||
, decltype(std::declval<_Ty>().end()) | |||
decltype(std::begin(std::declval<_Ty>())) | |||
, decltype(std::end(std::declval<_Ty>())) | |||
> | |||
> | |||
: std::true_type {}; | |||
//: is_iterator<decltype(std::declval<_Ty>().begin())> {}; | |||
: is_iterator<decltype(std::begin(std::declval<_Ty>()))> {}; | |||
template<class _Ty, size_t _Size> | |||
struct is_container<_Ty[_Size]> : std::true_type {}; | |||
template<class _Ty, size_t _Size> | |||
@@ -238,5 +247,29 @@ RESUMEF_NS | |||
template<class _Ty> | |||
constexpr bool is_container_v = is_container<remove_cvref_t<_Ty>>::value; | |||
template<class _Ty, class _Ety, class = std::void_t<>> | |||
struct is_container_of : std::false_type {}; | |||
template<class _Ty, class _Ety> | |||
struct is_container_of | |||
<_Ty, _Ety, | |||
std::void_t< | |||
decltype(std::begin(std::declval<_Ty>())) | |||
, decltype(std::end(std::declval<_Ty>())) | |||
> | |||
> | |||
: std::conjunction< | |||
is_iterator<decltype(std::begin(std::declval<_Ty>()))>, | |||
std::is_same<_Ety&, decltype(*std::begin(std::declval<_Ty>()))> | |||
> {}; | |||
template<class _Ty, size_t _Size> | |||
struct is_container_of<_Ty[_Size], _Ty> : std::true_type {}; | |||
template<class _Ty, size_t _Size> | |||
struct is_container_of<_Ty(&)[_Size], _Ty> : std::true_type {}; | |||
template<class _Ty, size_t _Size> | |||
struct is_container_of<_Ty(&&)[_Size], _Ty> : std::true_type {}; | |||
template<class _Ty, class _Ety> | |||
constexpr bool is_container_of_v = is_container_of<remove_cvref_t<_Ty>, _Ety>::value; | |||
} | |||
} |