From 63745ee91f7af6970fb62604e5069379251e7cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Tue, 3 Jun 2025 19:23:04 +0200 Subject: [PATCH] Add insertion operator for Grid class --- include/aoc/common/Grid.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; +}