rename input/output

This commit is contained in:
2022-11-06 19:46:43 -08:00
parent 6a34b0f309
commit 041c055f43
4 changed files with 10 additions and 10 deletions

View File

@@ -9,11 +9,11 @@
namespace intcode {
struct Input {
ValueType &pos;
ValueType &input;
};
struct Output {
ValueType val;
ValueType output;
};
struct Halt {};
@@ -32,8 +32,8 @@ template <std::invocable<ValueType&> Fin, std::invocable<ValueType> Fout, std::i
auto Advance(Machine & machine, Fin input, Fout output, Fhalt halt) {
return std::visit(overloaded{
[&](Halt) { return halt(); },
[&](Input i) { return input(i.pos); },
[&](Output o) { return output(o.val); },
[&](Input i) { return input(i.input); },
[&](Output o) { return output(o.output); },
}, Step(machine));
}

View File

@@ -6,11 +6,11 @@ BadInstruction::BadInstruction(char const* what)
: std::runtime_error{what} {}
auto StepInput(Machine & m, ValueType input) -> void {
std::get<Input>(Step(m)).pos = input;
std::get<Input>(Step(m)).input = input;
}
auto StepOutput(Machine & m) -> ValueType {
return std::get<Output>(Step(m)).val;
return std::get<Output>(Step(m)).output;
}
auto Step(Machine & m) -> std::variant<Input, Output, Halt> {