-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
从 boost.cobalt 学的 awaitable<T> 模板特化方法 #17
Conversation
看来编译出错了,我再改改! |
4ba6fad
to
ff929de
Compare
这次改对了。 ctest 成功 |
f58ddc6
to
a9283f4
Compare
9c7054d
to
599dfc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果能解释或修改这2个小问题,我觉得就可以合并了
include/ucoro/awaitable.hpp
Outdated
@@ -381,23 +354,24 @@ namespace ucoro | |||
} | |||
} | |||
|
|||
template <typename PromiseType> | |||
auto await_suspend(std::coroutine_handle<PromiseType> continuation) | |||
template <typename OT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OT 这个类型命名是有什么考虑,还是随意的命名?
如果是随意的,应该考虑用一个更有意义且看起来更具普遍性的类型命名。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是随意的命名。主要是 T 这种通用名被外面的模板类占用了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果没有特别的原因,我的建议是继续使用之前的类型名称 PromiseType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前的 PromiseType 还得在里面加约束,PromiseType 必须得是 awaitable<T> 的一种。不然并不能用这个代码。因为别人的 promise 类型可没 local_ 这个对象。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果使用 std::coroutine_handle ,还得加 requires ( is_promise_type <PromiseType> )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不加约束是不行的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你用 OT 的时候,我也没看到你有加约束啊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要么非要用 std::coroutine_handle<PromiseType> continuation 这样的写法,然后给 PromiseType 上 concept 约束。
要么用 std::coroutine_handle<awaitable_type<AnyType>> continuation 这样只写法。让编译器自动约束。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你用 OT 的时候,我也没看到你有加约束啊
你没解释我这个问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不加约束编译测试没通过,重新 push 了个加约束的版本了。
原来的代码是用
if constexpr (std::is_base_of_v<awaitable_promise_base, PromiseType>)
这个加约束的。 因为 awaitable_promise_base 没了,所以这个检查就不行了。所以要换个方式写约束。
这里是必须要有约束的呀。
ead41af
to
c4f25dc
Compare
awaitable<T> 和 awaitable<void> 行为逻辑略有不同。 最初使用的是特化 awaitable_promise_type<void> 的方式 现在改为不特化 awaitable, 也不特化 awaitable_promise_type, 而是将针对 T 不同的部分,作为 awaitable_promise_value<T> 然后特化 awaitable_promise_value<void> 即可。 这样需要被特化的代码量有所减少。
c4f25dc
to
75200a2
Compare
include/ucoro/awaitable.hpp
Outdated
@@ -381,23 +354,24 @@ namespace ucoro | |||
} | |||
} | |||
|
|||
template <typename PromiseType> | |||
template <typename AnyType, typename PromiseType = awaitable_promise<AnyType>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <typename AnyType, typename PromiseType = awaitable_promise<AnyType>>
这里是多此一举的,我的意思怎么还不能明白?
template <typename PromiseType>
这样就就可以了,而不是随意的名字 OT 或 AnyType
include/ucoro/awaitable.hpp
Outdated
@@ -381,23 +354,24 @@ namespace ucoro | |||
} | |||
} | |||
|
|||
template <typename PromiseType> | |||
auto await_suspend(std::coroutine_handle<PromiseType> continuation) | |||
template <typename OT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你的 OT 就不失常?为什么改成 PromiseType 就失常了?
include/ucoro/awaitable.hpp
Outdated
@@ -381,23 +354,24 @@ namespace ucoro | |||
} | |||
} | |||
|
|||
template <typename PromiseType> | |||
auto await_suspend(std::coroutine_handle<PromiseType> continuation) | |||
template <typename OT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你用 OT 的时候,我也没看到你有加约束啊
include/ucoro/awaitable.hpp
Outdated
@@ -381,23 +354,24 @@ namespace ucoro | |||
} | |||
} | |||
|
|||
template <typename PromiseType> | |||
auto await_suspend(std::coroutine_handle<PromiseType> continuation) | |||
template <typename OT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你用 OT 的时候,我也没看到你有加约束啊
你没解释我这个问题
awaitable<T> 和 awaitable<void> 行为逻辑略有不同。
最初使用的是特化 awaitable_promise_type<void> 的方式
现在改为不特化 awaitable, 也不特化 awaitable_promise_type,
而是将针对 T 不同的部分,作为 awaitable_promise_value<T>
然后特化 awaitable_promise_value<void> 即可。
这样需要被特化的代码量有所减少。