|
3 | 3 |
|
4 | 4 | USING_AH_NAMESPACE; |
5 | 5 |
|
| 6 | +template <class T, size_t N> |
| 7 | +std::ostream &operator<<(std::ostream &os, const AH::Array<T, N> &a) { |
| 8 | + if (N < 1) |
| 9 | + return os << "{}"; |
| 10 | + os << '{'; |
| 11 | + for (size_t i = 0; i < N - 1; ++i) |
| 12 | + os << a[i] << ", "; |
| 13 | + return os << a[N - 1] << '}'; |
| 14 | +} |
| 15 | + |
| 16 | +template <class T, size_t N, bool Reverse, bool Const> |
| 17 | +std::ostream &operator<<(std::ostream &os, |
| 18 | + const AH::ArraySlice<T, N, Reverse, Const> &a) { |
| 19 | + if (N < 1) |
| 20 | + return os << "{}"; |
| 21 | + os << '{'; |
| 22 | + for (size_t i = 0; i < N - 1; ++i) |
| 23 | + os << a[i] << ", "; |
| 24 | + return os << a[N - 1] << '}'; |
| 25 | +} |
| 26 | + |
6 | 27 | TEST(Array, initializeAndRetrieve) { |
7 | 28 | Array<int, 6> arr = {0, 1, 2, 3, 4, 5}; |
8 | 29 | for (int i = 0; i < 6; i++) |
@@ -266,12 +287,16 @@ TEST(generateArray, simpleNoType) { |
266 | 287 | EXPECT_EQ(x, y); |
267 | 288 | } |
268 | 289 |
|
| 290 | +struct S { |
| 291 | + int i; |
| 292 | + float f; |
| 293 | + bool operator!=(S o) const { return this->i != o.i || this->f != o.f; } |
| 294 | + friend std::ostream &operator<<(std::ostream &os, S s) { |
| 295 | + return os << "S{" << s.i << ", " << s.f << "}"; |
| 296 | + } |
| 297 | +}; |
| 298 | + |
269 | 299 | TEST(fillArray, simple) { |
270 | | - struct S { |
271 | | - int i; |
272 | | - float f; |
273 | | - bool operator!=(S o) const { return this->i != o.i || this->f != o.f; } |
274 | | - }; |
275 | 300 | auto x = fillArray<S, 4>(2, 3.14f); |
276 | 301 | Array<S, 4> y = {{{2, 3.14f}, {2, 3.14f}, {2, 3.14f}, {2, 3.14f}}}; |
277 | 302 | EXPECT_EQ(x, y); |
|
0 commit comments