From 4d082159107b6320b1d8941a8e1aaeca1ba5720d Mon Sep 17 00:00:00 2001
From: Max Kahnt <max.kahnt@fu-berlin.de>
Date: Thu, 5 Oct 2017 15:08:11 +0200
Subject: [PATCH] Add iteration helper over matrix elements.

---
 dune/matrix-vector/algorithm.hh | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/dune/matrix-vector/algorithm.hh b/dune/matrix-vector/algorithm.hh
index 81d55f7..c2d3605 100644
--- a/dune/matrix-vector/algorithm.hh
+++ b/dune/matrix-vector/algorithm.hh
@@ -40,6 +40,15 @@ void sparseRangeFirst(Range&& range, F&& f)
   f(*range.begin());
 }
 
+template <class Matrix, class F>
+void sparseMatrixFor(Matrix&& m, F&& f) {
+  sparseRangeFor(m, [&](auto&& row, auto&& i) {
+    sparseRangeFor(row, [&](auto&& col, auto&& j) {
+      f(col, i, j);
+    });
+  });
+}
+
 } // namespace MatrixVector
 } // namespace Dune
 
-- 
GitLab