int inner_constructions = 0;
int inner_destructions = 0;
struct Inner {
Inner() {
std::cout << this << "->Inner()\n" << std::flush;
inner_constructions++;
}
~Inner() {
std::cout << this << "->~Inner()\n" << std::flush;
inner_destructions++;
}
Inner(const Inner&) = delete;
Inner& operator=(const Inner&) = delete;
Inner(Inner&&) = delete;
Inner& operator=(Inner&&) = delete;
};
struct Value { Inner inner; };
struct Yielder {
struct promise_type;
using Handle = std::coroutine_handle;
struct promise_type {
Yielder get_return_object() { return Yielder{Handle::from_promise(*this)}; }
std::suspend_never initial_suspend() const noexcept { return {}; }
std::suspend_always final_suspend() const noexcept { return {}; }
void unhandled_exception() {}
std::suspend_always yield_value(const Value& v) noexcept {
value = &v;
return {};
}
const Value* value = nullptr;
};
// Destroy triggers the destructors for the coroutine state…