]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Bugfix: Provide const TensorIndicesHelper<>::extract variant
authorMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 22:34:47 +0000 (17:34 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 22:35:29 +0000 (17:35 -0500)
It is necessary to also deal with const references...

include/deal.II/base/tensor.h

index cec13691a6a325514215bba8895822e36a20d1e4..4def2b2bbed5840cad68562471a901ed2e555f20 100644 (file)
@@ -803,6 +803,15 @@ namespace internal
       return TensorIndicesHelper<rank_ - 1>::template extract<rank, dim, Number>(
         t[indices[rank - rank_]], indices);
     }
+
+    template<int rank, int dim, typename Number>
+    static inline
+    const Number &extract(const Tensor<rank_,dim,Number> &t, const TableIndices<rank> &indices)
+    {
+      Assert (indices[rank - rank_]<dim, ExcIndexRange (indices[rank - rank_], 0, dim));
+      return TensorIndicesHelper<rank_ - 1>::template extract<rank, dim, Number>(
+        t[indices[rank - rank_]], indices);
+    }
   };
 
   template<> struct TensorIndicesHelper<1>
@@ -814,6 +823,14 @@ namespace internal
       Assert (indices[rank - 1]<dim, ExcIndexRange (indices[rank - 1], 0, dim));
       return t[indices[rank-1]];
     }
+
+    template<int rank, int dim, typename Number>
+    static inline
+    const Number &extract(const Tensor<1,dim,Number> &t, const TableIndices<rank> &indices)
+    {
+      Assert (indices[rank - 1]<dim, ExcIndexRange (indices[rank - 1], 0, dim));
+      return t[indices[rank-1]];
+    }
   };
 } /* internal */
 
@@ -905,7 +922,7 @@ Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> &indices) const
 {
   Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<rank_,0,Number>"));
   Assert (indices[0]<dim, ExcIndexRange (indices[0], 0, dim));
-  return internal::TensorIndicesHelper<rank_>::extract(*this, indices);
+  return internal::TensorIndicesHelper<rank_>::template extract<rank_, dim, Number>(*this, indices);
 }
 
 
@@ -916,7 +933,7 @@ Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> &indices)
 {
   Assert(dim != 0, ExcMessage("Cannot access an object of type Tensor<rank_,0,Number>"));
   Assert (indices[0]<dim, ExcIndexRange (indices[0], 0, dim));
-  return internal::TensorIndicesHelper<rank_>::extract(*this, indices);
+  return internal::TensorIndicesHelper<rank_>::template extract<rank_, dim, Number>(*this, indices);
 }
 
 

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.