diff --git a/include/aoc/common/Grid.hpp b/include/aoc/common/Grid.hpp index 02c165b..0b803b7 100644 --- a/include/aoc/common/Grid.hpp +++ b/include/aoc/common/Grid.hpp @@ -15,6 +15,7 @@ #pragma once +#include #include #include @@ -65,4 +66,20 @@ class Grid size_t nRows_; size_t nColumns_; std::unique_ptr data_; + friend std::ostream& operator<< <>(std::ostream& os, const Grid& rhs); }; + +template +std::ostream& operator<<(std::ostream& os, const Grid& rhs) +{ + size_t i{ 0 }; + for (size_t j = 0; j < rhs.getNRows(); j++) + { + for (; i < j * rhs.getNColumns(); i++) + { + os << rhs.data_[i] << ' '; + } + os << std::endl; + } + return os; +}