Hard
A coroutine taking a const std::string& parameter
Compiled as C++20, what happens when this program runs?
main.cpp
#include <coroutine>
#include <iostream>
#include <string>
struct Task {
struct promise_type {
Task get_return_object() {
return Task{std::coroutine_handle<promise_type>::from_promise(*this)};
}
std::suspend_always initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
std::coroutine_handle<promise_type> handle;
};
Task logValue(const std::string& value) {
std::cout << "value: " << value << std::endl;
co_return;
}
int main() {
Task t = logValue(std::string("hello"));
t.handle.resume();
}28 of 117 in C++