Skip to content
Snippets Groups Projects
Commit acb0259f authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add output to Array. Now Vector uses Array output to print data.

parent 5f780832
No related branches found
No related tags found
1 merge request!105Add NaNHelper utility
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define VECTOR_HPP #define VECTOR_HPP
#include <utils/Array.hpp> #include <utils/Array.hpp>
#include <utils/NaNHelper.hpp>
#include <utils/PugsAssert.hpp> #include <utils/PugsAssert.hpp>
#include <utils/PugsMacros.hpp> #include <utils/PugsMacros.hpp>
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
...@@ -29,13 +28,7 @@ class Vector // LCOV_EXCL_LINE ...@@ -29,13 +28,7 @@ class Vector // LCOV_EXCL_LINE
friend std::ostream& friend std::ostream&
operator<<(std::ostream& os, const Vector& x) operator<<(std::ostream& os, const Vector& x)
{ {
if (x.size() > 0) { return os << x.m_values;
os << 0 << ':' << NaNHelper(x[0]);
}
for (size_t i = 1; i < x.size(); ++i) {
os << ' ' << i << ':' << NaNHelper(x[i]);
}
return os;
} }
friend Vector<std::remove_const_t<DataType>> friend Vector<std::remove_const_t<DataType>>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define ARRAY_HPP #define ARRAY_HPP
#include <utils/InvalidData.hpp> #include <utils/InvalidData.hpp>
#include <utils/NaNHelper.hpp>
#include <utils/PugsAssert.hpp> #include <utils/PugsAssert.hpp>
#include <utils/PugsMacros.hpp> #include <utils/PugsMacros.hpp>
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
...@@ -23,6 +24,17 @@ class [[nodiscard]] Array ...@@ -23,6 +24,17 @@ class [[nodiscard]] Array
friend Array<std::add_const_t<DataType>>; friend Array<std::add_const_t<DataType>>;
public: 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 PUGS_INLINE size_t size() const noexcept
{ {
return m_values.extent(0); return m_values.extent(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment