#ifndef INTCODE_INTERPRETER_HPP_ #define INTCODE_INTERPRETER_HPP_ #include #include #include namespace intcode { struct Input { ValueType &pos; }; struct Output { ValueType val; }; struct Halt {}; auto Step(Machine & m) -> std::variant; struct BadInstruction : public std::runtime_error { explicit BadInstruction(char const* what); }; template auto Run(Machine & machine, Fin input, Fout output) -> void { while (std::visit(overloaded{ [](Halt) { return false; }, [&](Input arg) { arg.pos = input(); return true; }, [&](Output arg) { output(arg.val); return true; }}, Step(machine))); } } // namespace #endif