29 for (
auto [idx, symbol] : std::views::enumerate(str))
32 if (idx >
static_cast<std::size_t
>(std::numeric_limits<int>::max()))
34 throw std::out_of_range(
35 "Input string length exceeds maximum signed integer capacity of the tape."
38 this->cells_[
static_cast<int>(idx)] = symbol;
51 if (it == this->
cells_.end())
69 int min_idx = this->head_pos_;
70 int max_idx = this->head_pos_;
73 if (!this->cells_.empty())
75 min_idx = std::min(min_idx, this->cells_.begin()->first);
76 max_idx = std::max(max_idx, this->cells_.rbegin()->first);
80 min_idx = std::min(min_idx, this->head_pos_ - 2);
81 max_idx = std::max(max_idx, this->head_pos_ + 2);
84 for (
int i = min_idx; i <= max_idx; ++i)
86 auto it = this->cells_.find(i);
88 os <<
"| " << s <<
" ";
94 for (
int i = min_idx; i <= max_idx; ++i)
96 if (i == this->head_pos_)
Represents a formal string (w) consisting of a finite sequence of Symbols.
Represents a single symbol on the Turing Machine's tape.
void print(std::ostream &os=std::cout) const noexcept
Prints the symbol's character representation to the specified output stream.
Simulates the bilateral infinite tape layout of a Turing Machine.
std::map< int, Symbol > cells_
Memory cells mapping coordinates to written Symbols.
void print(std::ostream &os=std::cout) const noexcept
Renders the active layout of the tape and the head tracking to an output stream.
Tape() noexcept
Default constructor.
Symbol read() const noexcept
Reads the symbol currently located under the tape head.
int head_pos_
Current mathematical index coordinate of the head.
constexpr char kBlank
Representation of the default blank symbol used to fill the Turing Machine's tape.
std::ostream & operator<<(std::ostream &os, const Tape &tape) noexcept
Global stream insertion operator overload.
Tape class representing the infinite memory structure of the Turing Machine.