From acb0259f52bb57df6cf896d42617aa8be7fbda2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Sat, 31 Jul 2021 16:10:51 +0200
Subject: [PATCH] Add output to Array. Now Vector uses Array output to print
 data.

---
 src/algebra/Vector.hpp |  9 +--------
 src/utils/Array.hpp    | 12 ++++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/algebra/Vector.hpp b/src/algebra/Vector.hpp
index 6950df9d7..c918ed409 100644
--- a/src/algebra/Vector.hpp
+++ b/src/algebra/Vector.hpp
@@ -2,7 +2,6 @@
 #define VECTOR_HPP
 
 #include <utils/Array.hpp>
-#include <utils/NaNHelper.hpp>
 #include <utils/PugsAssert.hpp>
 #include <utils/PugsMacros.hpp>
 #include <utils/PugsUtils.hpp>
@@ -29,13 +28,7 @@ class Vector   // LCOV_EXCL_LINE
   friend std::ostream&
   operator<<(std::ostream& os, const Vector& x)
   {
-    if (x.size() > 0) {
-      os << 0 << ':' << NaNHelper(x[0]);
-    }
-    for (size_t i = 1; i < x.size(); ++i) {
-      os << ' ' << i << ':' << NaNHelper(x[i]);
-    }
-    return os;
+    return os << x.m_values;
   }
 
   friend Vector<std::remove_const_t<DataType>>
diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp
index e2a4e5c71..bae84f114 100644
--- a/src/utils/Array.hpp
+++ b/src/utils/Array.hpp
@@ -2,6 +2,7 @@
 #define ARRAY_HPP
 
 #include <utils/InvalidData.hpp>
+#include <utils/NaNHelper.hpp>
 #include <utils/PugsAssert.hpp>
 #include <utils/PugsMacros.hpp>
 #include <utils/PugsUtils.hpp>
@@ -23,6 +24,17 @@ class [[nodiscard]] Array
   friend Array<std::add_const_t<DataType>>;
 
  public:
+  friend std::ostream& operator<<(std::ostream& os, const Array& x)
+  {
+    if (x.size() > 0) {
+      os << 0 << ':' << NaNHelper(x[0]);
+    }
+    for (size_t i = 1; i < x.size(); ++i) {
+      os << ' ' << i << ':' << NaNHelper(x[i]);
+    }
+    return os;
+  }
+
   PUGS_INLINE size_t size() const noexcept
   {
     return m_values.extent(0);
-- 
GitLab