diff --git a/ostd/coroutine.hh b/ostd/coroutine.hh index 98f45a4..d7e959d 100644 --- a/ostd/coroutine.hh +++ b/ostd/coroutine.hh @@ -342,7 +342,7 @@ struct coroutine: detail::coro_base { } operator bool() const { - return this->p_ctx.is_done(); + return !this->p_ctx.is_done(); } R operator()(A ...args) { @@ -371,7 +371,7 @@ struct generator: input_range> { generator(F &&func, size_t ss = COROUTINE_DEFAULT_STACK_SIZE): p_ptr(new coroutine{std::forward(func), ss}) { - p_item = (*p_ptr)(); + pop_front(); } bool empty() const { @@ -379,7 +379,7 @@ struct generator: input_range> { } void pop_front() { - if (!*p_ptr) { + if (*p_ptr) { p_item = (*p_ptr)(); } else { p_item = std::nullopt;