From c1a568a602e63bf2d550cd5bcd98f54a1fe6f979 Mon Sep 17 00:00:00 2001
From: Tobias Malkmus <tomalk@mathematik.uni-freiburg.de>
Date: Thu, 27 Feb 2014 16:12:32 +0100
Subject: [PATCH] [densematrix] fix densematrix iterator for row_reference !=
 row_type&

Add additional template parameter R (default T&) to handle the case row_reference != row_type&.
---
 dune/common/densematrix.hh |  4 ++--
 dune/common/densevector.hh | 24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/dune/common/densematrix.hh b/dune/common/densematrix.hh
index ee253e396..aac3c5a79 100644
--- a/dune/common/densematrix.hh
+++ b/dune/common/densematrix.hh
@@ -250,7 +250,7 @@ namespace Dune
 
     //===== iterator interface to rows of the matrix
     //! Iterator class for sequential access
-    typedef DenseIterator<DenseMatrix,row_type> Iterator;
+    typedef DenseIterator<DenseMatrix,row_type,row_reference> Iterator;
     //! typedef for stl compliant access
     typedef Iterator iterator;
     //! rename the iterators for easier access
@@ -285,7 +285,7 @@ namespace Dune
     }
 
     //! Iterator class for sequential access
-    typedef DenseIterator<const DenseMatrix,const row_type> ConstIterator;
+    typedef DenseIterator<const DenseMatrix,const row_type,const_row_reference> ConstIterator;
     //! typedef for stl compliant access
     typedef ConstIterator const_iterator;
     //! rename the iterators for easier access
diff --git a/dune/common/densevector.hh b/dune/common/densevector.hh
index 6929090f5..7a30b277e 100644
--- a/dune/common/densevector.hh
+++ b/dune/common/densevector.hh
@@ -116,13 +116,15 @@ namespace Dune {
 
      provides sequential access to DenseVector, FieldVector and FieldMatrix
    */
-  template<class C, class T>
+  template<class C, class T, class R =T&>
   class DenseIterator :
-    public Dune::RandomAccessIteratorFacade<DenseIterator<C,T>,T, T&, std::ptrdiff_t>
+    public Dune::RandomAccessIteratorFacade<DenseIterator<C,T,R>,T, R, std::ptrdiff_t>
   {
-    friend class DenseIterator<typename remove_const<C>::type, typename remove_const<T>::type >;
-    friend class DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type >;
+    friend class DenseIterator<typename remove_const<C>::type, typename remove_const<T>::type, typename mutable_reference<R>::type >;
+    friend class DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type, typename const_reference<R>::type >;
 
+    typedef DenseIterator<typename remove_const<C>::type, typename remove_const<T>::type, typename mutable_reference<R>::type > MutableIterator;
+    typedef DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type, typename const_reference<R>::type > ConstIterator;
   public:
 
     /**
@@ -144,23 +146,27 @@ namespace Dune {
       : container_(&cont), position_(pos)
     {}
 
-    DenseIterator(const DenseIterator<typename remove_const<C>::type, typename remove_const<T>::type >& other)
+    DenseIterator(const MutableIterator & other)
+      : container_(other.container_), position_(other.position_)
+    {}
+
+    DenseIterator(const ConstIterator & other)
       : container_(other.container_), position_(other.position_)
     {}
 
     // Methods needed by the forward iterator
-    bool equals(const DenseIterator<typename remove_const<C>::type,typename remove_const<T>::type>& other) const
+    bool equals(const MutableIterator &other) const
     {
       return position_ == other.position_ && container_ == other.container_;
     }
 
 
-    bool equals(const DenseIterator<const typename remove_const<C>::type,const typename remove_const<T>::type>& other) const
+    bool equals(const ConstIterator & other) const
     {
       return position_ == other.position_ && container_ == other.container_;
     }
 
-    T& dereference() const {
+    R dereference() const {
       return container_->operator[](position_);
     }
 
@@ -174,7 +180,7 @@ namespace Dune {
     }
 
     // Additional function needed by RandomAccessIterator
-    T& elementAt(DifferenceType i) const {
+    R elementAt(DifferenceType i) const {
       return container_->operator[](position_+i);
     }
 
-- 
GitLab