Skip to content

Commit

Permalink
aoc_lib: get field width for values in repr for Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Dec 10, 2024
1 parent 6fab347 commit aabcc8c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aoc_lib/ds/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,17 @@ Grid(std::vector<std::vector<T>> &&) -> Grid<T>;
template <class T>
std::ostream &print_repr(std::ostream &os, const aoc::ds::Grid<T> &grid,
const bool result) {
// Get the current field width (from std::setw()) which we will use for the
// individual values. Also set it to 0, as it shouldn't apply to the
// initial '['.
auto field_width = os.width(0);
for (int i = 0; const auto &row : grid) {
os << (i == 0 ? '[' : ' ') << '[';
for (int j = 0; const auto &value : row) {
if (j != 0) {
os << " ";
}
os << std::setw(12) << pretty_print::repr(value, result);
os << std::setw(field_width) << pretty_print::repr(value, result);
++j;
}
++i;
Expand Down

0 comments on commit aabcc8c

Please sign in to comment.