#include namespace intcode { Machine::Machine() : rom_{}, ram_{}, pc_{0}, base_{0} {} Machine::Machine(std::vector program) : rom_{std::move(program)}, ram_{}, pc_{0}, base_{0} {} auto Machine::At(std::size_t const i) -> ValueType & { return i < rom_.size() ? rom_[i] : ram_[i]; } auto Machine::At(std::size_t const i) const -> ValueType { if (i < rom_.size()) return rom_[i]; if (auto it = ram_.find(i); it != ram_.end()) { return it->second; } return 0; } auto Machine::Rel(std::size_t const i) -> ValueType & { return At(base_ + i); } auto Machine::Rebase(std::size_t const offset) -> void { base_ += offset; } auto Machine::Next() -> ValueType & { return At(pc_++); } auto Machine::Goto(std::size_t const address) -> void { pc_ = address; } } // namespace