Ошибка: «Обещание сопрограммы должно объявлять либо «return_value», либо «return_void»
Пример взят из блога Дэвида Мазьераhttps://www.scs.stanford.edu/~dm/blog/c++-coroutines.html
, который работает под другим компилятор, GCC 10.2.
Я не могу скомпилировать исходный код в VS2019.
Код: Выделить всё
#include
#include
#include
#include
struct ReturnObject {
struct promise_type {
ReturnObject get_return_object() { return {}; }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return{}; }
void unhandled_exception() {}
};
};
struct Awaiter {
std::coroutine_handle* hp_;
constexpr bool await_ready() const noexcept { return false; }
void await_suspend(std::coroutine_handle h) { *hp_ = h; }
constexpr void await_resume() const noexcept {}
};
ReturnObject
counter(std::coroutine_handle* continuation_out)
{
Awaiter a{ continuation_out };
for (unsigned i = 0;; ++i) {
co_await a;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/67306337/a-coroutines-promise-must-declare-either-return-value-or-return-void-erro[/url]
Мобильная версия