From 2b4816bf845f16bc4bbefc74a3fd4ab6689b45d0 Mon Sep 17 00:00:00 2001
From: Max Kahnt <max.kahnt@fu-berlin.de>
Date: Mon, 25 Sep 2017 11:57:19 +0200
Subject: [PATCH] Refactor generic vector tools:

 - remove outdated editor hints
 - fix indentation
 - use range based for loop
 - add a typedef for the central helper specialization type
---
 dune/matrix-vector/genericvectortools.hh | 47 ++++++++++--------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/dune/matrix-vector/genericvectortools.hh b/dune/matrix-vector/genericvectortools.hh
index b2b5de3..f6bdc2f 100644
--- a/dune/matrix-vector/genericvectortools.hh
+++ b/dune/matrix-vector/genericvectortools.hh
@@ -1,5 +1,3 @@
-// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
-// vi: set et ts=8 sw=4 sts=4:
 #ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
 #define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
 
@@ -17,38 +15,33 @@ namespace Dune {
 namespace MatrixVector {
 namespace Generic { // TODO change namespace name
 
-template<class Vector> struct Helper;
+template <class Vector>
+struct Helper;
 
 //! Write vector to given stream
-template<class Vector>
-void writeBinary(std::ostream& s, const Vector& v)
-{ Dune::MatrixVector::Generic::Helper<Vector>::writeBinary(s, v); }
+template <class Vector>
+void writeBinary(std::ostream& s, const Vector& v) {
+  Helper<Vector>::writeBinary(s, v);
+}
+
 
 template <class Vector>
-struct Helper
-{
-    static void writeBinary(std::ostream& s, const Vector& v)
-    {
-        typename Vector::const_iterator it = v.begin();
-        typename Vector::const_iterator end = v.end();
-        for(; it!=end; ++it)
-            Helper<typename Vector::block_type>::writeBinary(s, *it);
-    }
-};
+struct Helper {
+  static void writeBinary(std::ostream& s, const Vector& v) {
+    for (auto&& vi : v)
+      Generic::writeBinary(s, vi);
+  }
 
-template<class Field, int n>
-struct Helper<Dune::FieldVector<Field,n>>
-{
-    static void writeBinary(std::ostream& s, const Dune::FieldVector<Field,n>& v)
-    {
-        typedef typename Dune::FieldVector<Field,n> Vector;
-        typename Vector::const_iterator it = v.begin();
-        typename Vector::const_iterator end = v.end();
-        for(; it!=end; ++it)
-            s.write(reinterpret_cast<const char*>(&(*it)), sizeof(Field));
-    }
 };
 
+template <class Field, int n>
+struct Helper<FieldVector<Field, n>> {
+  using Vector = FieldVector<Field, n>;
+
+  static void writeBinary(std::ostream& s, const Vector& v) {
+    for (auto&& vi : v)
+      s.write(reinterpret_cast<const char*>(&vi), sizeof(Field));
+  }
 
 
 } // end namespace Generic
-- 
GitLab