]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement operator<<(ostream,Vector) in a better way.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 5 May 2020 14:42:25 +0000 (08:42 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 5 May 2020 14:42:25 +0000 (08:42 -0600)
include/deal.II/lac/vector.h

index a82e125c3db855ed2e5ed239790a555790f21721..3893218ab1cce93dafc07fe553d8bfcd4a81c972 100644 (file)
@@ -1369,10 +1369,18 @@ swap(Vector<Number> &u, Vector<Number> &v)
  */
 template <typename number>
 inline std::ostream &
-operator<<(std::ostream &os, const Vector<number> &v)
+operator<<(std::ostream &out, const Vector<number> &v)
 {
-  v.print(os);
-  return os;
+  Assert(v.size() != 0, ExcEmptyObject());
+  AssertThrow(out, ExcIO());
+
+  for (typename Vector<number>::size_type i = 0; i < v.size() - 1; ++i)
+    out << v(i) << ' ';
+  out << v(v.size() - 1);
+
+  AssertThrow(out, ExcIO());
+
+  return out;
 }
 
 /*@}*/

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.