Coroutines (C++20)
From cppreference.com
A coroutine is a function that can suspend execution to be resumed later. Coroutines are stackless: they suspend execution by returning to the caller.
A function is a coroutine if its definition does any of the following:
- uses the keyword co_return for its return statement
- uses the keyword co_yield to suspend execution with a value
generator<int> gen(int next, int inc = 1) { for(;;) { co_yield next; next += inc; } }
- uses the co_await operator or the co_await form of of range-for loop
Restrictions
Coroutines cannot use variadic arguments, plain return statements, or placeholder return types (auto or Concept).
Constexpr functions, constructors, destructors, and the main function cannot be coroutines.
Explanation
This section is incomplete Reason: I think we can write it all on one page |