| 1 |
#include <coroutine> |
| 2 |
|
| 3 |
struct coroutine { |
| 4 |
struct promise_type { |
| 5 |
auto get_return_object() { return coroutine(); } |
| 6 |
auto initial_suspend() { return std::suspend_always(); } |
| 7 |
auto yield_value(int) { return std::suspend_always(); } |
| 8 |
void return_void() {} |
| 9 |
auto final_suspend() noexcept { return std::suspend_always(); } |
| 10 |
void unhandled_exception() {} |
| 11 |
}; |
| 12 |
}; |
| 13 |
|
| 14 |
int main() { |
| 15 |
auto f = [](auto max) -> coroutine { |
| 16 |
for (int i = 0; i < max; ++i) { |
| 17 |
co_yield i; |
| 18 |
} |
| 19 |
}; |
| 20 |
|
| 21 |
f(10); |
| 22 |
|
| 23 |
// From PR98976 |
| 24 |
auto foo = [](auto&&) -> coroutine { |
| 25 |
switch (42) { |
| 26 |
case 42: |
| 27 |
co_return; |
| 28 |
} |
| 29 |
}; |
| 30 |
foo(1); |
| 31 |
|
| 32 |
} |