Add insertion operator for Grid class
This commit is contained in:
parent
05d627a176
commit
63745ee91f
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <aoc/common/Point2.hpp>
|
#include <aoc/common/Point2.hpp>
|
||||||
@ -65,4 +66,20 @@ class Grid
|
|||||||
size_t nRows_;
|
size_t nRows_;
|
||||||
size_t nColumns_;
|
size_t nColumns_;
|
||||||
std::unique_ptr<T[]> data_;
|
std::unique_ptr<T[]> data_;
|
||||||
|
friend std::ostream& operator<< <>(std::ostream& os, const Grid<T>& rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Grid<T>& 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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user