online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <coroutine> #include <iostream> struct Generator { struct promise_type { long long current_value; Generator get_return_object() { return Generator{std::coroutine_handle<promise_type>::from_promise(*this)}; } std::suspend_always initial_suspend() { return {}; } std::suspend_always final_suspend() noexcept { return {}; } std::suspend_always yield_value(long long value) { current_value = value; return {}; } void return_void() {} void unhandled_exception() {} }; std::coroutine_handle<promise_type> handle; Generator(std::coroutine_handle<promise_type> h) : handle(h) {} ~Generator() { if (handle) handle.destroy(); } long long next() { handle.resume(); return handle.promise().current_value; } }; Generator fibonacci() { long long a = 0, b = 1; while (true) { co_yield a; auto tmp = a + b; a = b; b = tmp; } } int main() { auto gen = fibonacci(); long long n = gen.next(); while (n < 100) { std::cout << n << " "; n = gen.next(); } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue