Replies: 2 comments 1 reply
-
我感觉可以试试? |
Beta Was this translation helpful? Give feedback.
0 replies
-
template <typename T>
class LazyPromise : public LazyPromiseBase {
public:
LazyPromise() noexcept {}
~LazyPromise() noexcept {}
Lazy<T> get_return_object() noexcept;
template <typename V>
void return_value(V&& value) noexcept(
std::is_nothrow_constructible_v<
T, V&&>) requires std::is_convertible_v<V&&, T> {
_value.emplace(std::forward<V>(value));
}
void unhandled_exception() noexcept {
_value.setException(std::current_exception());
}
public:
T& result() & {
return _value.value();
}
T&& result() && {
return std::move(_value).value();
}
Try<T> tryResult() noexcept {
return std::move(_value);
}
Try<T> _value;
};
template <>
class LazyPromise<void> : public LazyPromiseBase {
public:
Lazy<void> get_return_object() noexcept;
void return_void() noexcept {}
void unhandled_exception() noexcept {
_value.setException(std::current_exception());
}
void result() {
return _value.value();
}
Try<void> tryResult() noexcept {
return std::move(_value);
}
public:
Try<void> _value;
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
async_simple/async_simple/coro/Lazy.h
Lines 119 to 184 in aa1d718
感觉这里和
Try
差不多,有没有考虑将数据成员直接写成Try<T>
呢,直接用Try
也会简洁一些?很多代码可以合并,除了return_xxx
的,将相同逻辑代码移至LazyPromiseBase
?差不多最后只留一个return_xxx
Beta Was this translation helpful? Give feedback.
All reactions