doasku

Sudoku solver
git clone git://git.dimitrijedobrota.com/doasku.git
Log | Files | Refs | README | LICENSE

commit 7852ef886ef95b2233d9cd52bef2b2b4536ac6fe
parent 026fc34262e261516f73ea642afee4c838dc2056
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 11 Apr 2024 23:16:45 +0200

Remove explicit from conversion operator

Diffstat:
Mmain.cpp | 42+++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/main.cpp b/main.cpp @@ -18,7 +18,7 @@ struct cord_t { cord_t(uint8_t row, uint8_t col) : value(row * 3 + col) { assert(row < 3 && col < 3); } cord_t(uint8_t value) : value(value) { assert(value < 9); } - explicit operator uint8_t() const { return value; } + operator uint8_t() const { return value; } uint8_t row() const { return value / 3; } uint8_t col() const { return value % 3; } @@ -44,7 +44,7 @@ class acord_t { std::tuple<cord_t, cord_t> relative() const { return {subgrid_i, field_i}; } friend std::ostream &operator<<(std::ostream &os, acord_t acord) { - return os << std::format("({}, {})", acord.row(), acord.col()); + return os << std::format("(({}, {}))", acord.row(), acord.col()); } private: @@ -502,7 +502,7 @@ class Grid { for (uint8_t j = 0; j < 9; j++) { const cord_t subgrid = {uint8_t(i / 3), uint8_t(j / 3)}; const cord_t field = {uint8_t(i % 3), uint8_t(j % 3)}; - std::bitset<9> value = subgrids[(uint8_t)subgrid].get((uint8_t)field); + std::bitset<9> value = subgrids[subgrid].get(field); std::cout << value << " "; if (j % 3 == 2) std::cout << " "; } @@ -515,7 +515,7 @@ class Grid { for (uint8_t j = 0; j < 9; j++) { const cord_t subgrid = {uint8_t(i / 3), uint8_t(j / 3)}; const cord_t field = {uint8_t(i % 3), uint8_t(j % 3)}; - std::bitset<9> value = subgrids[(uint8_t)subgrid].get_ref((uint8_t)field); + std::bitset<9> value = subgrids[subgrid].get_ref(field); std::cout << value << " "; if (j % 3 == 2) std::cout << " "; } @@ -548,7 +548,7 @@ class Grid { for (uint8_t j = 0; j < 9; j++) { const cord_t subgrid = {uint8_t(i / 3), uint8_t(j / 3)}; const cord_t field = {uint8_t(i % 3), uint8_t(j % 3)}; - std::cout << (int)subgrids[(uint8_t)subgrid].get_value((uint8_t)field) << " "; + std::cout << (int)subgrids[subgrid].get_value(field) << " "; if (j % 3 == 2) std::cout << " "; } std::cout << std::endl; @@ -577,9 +577,9 @@ class Grid { void op_clear_row(operation_t op) { const auto [ab, val] = op; - const auto [r1, r2] = other_subgrid_row((uint8_t)ab.subgrid()); - _clear_row(r1, (uint8_t)ab.field(), val); - _clear_row(r2, (uint8_t)ab.field(), val); + const auto [r1, r2] = other_subgrid_row(ab.subgrid()); + _clear_row(r1, ab.field(), val); + _clear_row(r2, ab.field(), val); changed = true; } @@ -587,9 +587,9 @@ class Grid { void op_clear_col(operation_t op) { const auto [ab, val] = op; - const auto [c1, c2] = other_subgrid_col((uint8_t)ab.subgrid()); - _clear_col(c1, (uint8_t)ab.field(), val); - _clear_col(c2, (uint8_t)ab.field(), val); + const auto [c1, c2] = other_subgrid_col(ab.subgrid()); + _clear_col(c1, ab.field(), val); + _clear_col(c2, ab.field(), val); changed = true; } @@ -597,9 +597,9 @@ class Grid { void op_clear_row_rel(operation_t op) { const auto [ab, val] = op; - const auto [r1, r2] = other_subgrid_row((uint8_t)ab.row()); - _clear_row((r1 / 3) * 3 + (uint8_t)ab.col(), r1 % 3, val); - _clear_row((r2 / 3) * 3 + (uint8_t)ab.col(), r2 % 3, val); + const auto [r1, r2] = other_subgrid_row(ab.row()); + _clear_row((r1 / 3) * 3 + ab.col(), r1 % 3, val); + _clear_row((r2 / 3) * 3 + ab.col(), r2 % 3, val); changed = true; } @@ -607,9 +607,9 @@ class Grid { void op_clear_col_rel(operation_t op) { const auto [ab, val] = op; - const auto [c1, c2] = other_subgrid_row((uint8_t)ab.col()); - _clear_col((uint8_t)ab.row() * 3 + c1 / 3, c1 % 3, val); - _clear_col((uint8_t)ab.row() * 3 + c2 / 3, c2 % 3, val); + const auto [c1, c2] = other_subgrid_row(ab.col()); + _clear_col(ab.row() * 3 + c1 / 3, c1 % 3, val); + _clear_col(ab.row() * 3 + c2 / 3, c2 % 3, val); changed = true; } @@ -617,17 +617,17 @@ class Grid { void _set(acord_t ab, uint8_t value) { rows[ab.row()].set(ab.col(), value); cols[ab.col()].set(ab.row(), value); - subgrids[(uint8_t)ab.subgrid()].set((uint8_t)ab.field(), value); + subgrids[ab.subgrid()].set(ab.field(), value); _clear_row(ab.subgrid(), 0, value); _clear_row(ab.subgrid(), 1, value); _clear_row(ab.subgrid(), 2, value); - const auto [r1, r2] = other_subgrid_row((uint8_t)ab.subgrid()); + const auto [r1, r2] = other_subgrid_row(ab.subgrid()); _clear_row(r1, ab.field().row(), value); _clear_row(r2, ab.field().row(), value); - const auto [c1, c2] = other_subgrid_col((uint8_t)ab.subgrid()); + const auto [c1, c2] = other_subgrid_col(ab.subgrid()); _clear_col(c1, ab.field().col(), value); _clear_col(c2, ab.field().col(), value); } @@ -641,7 +641,7 @@ class Grid { } void _clear(acord_t ab, uint8_t value) { - subgrids[(uint8_t)ab.subgrid()].clear((uint8_t)ab.field(), value); + subgrids[ab.subgrid()].clear(ab.field(), value); rows[ab.row()].clear(ab.col(), value); cols[ab.col()].clear(ab.row(), value);