From: David Wells Date: Tue, 24 Aug 2021 18:27:24 +0000 (-0400) Subject: Use iterators in Tensor::unroll_recursion(). X-Git-Tag: v9.4.0-rc1~990^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3042d03f5f79de019fdf28c67eb5735194f767ee;p=dealii.git Use iterators in Tensor::unroll_recursion(). This makes the code applicable for more linear data structures than just Vector. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index d4fd088aa5..2f687d5d0b 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -407,10 +407,9 @@ private: /** * Internal helper function for unroll. */ - template - void - unroll_recursion(Vector &result, - unsigned int & start_index) const; + template + Iterator + unroll_recursion(const Iterator current, const Iterator end) const; // Allow an arbitrary Tensor to access the underlying values. template @@ -846,10 +845,9 @@ private: /** * Internal helper function for unroll. */ - template - void - unroll_recursion(Vector &result, - unsigned int & start_index) const; + template + Iterator + unroll_recursion(const Iterator current, const Iterator end) const; /** * This constructor is for internal use. It provides a way @@ -1213,15 +1211,16 @@ constexpr DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE template -template -inline void -Tensor<0, dim, Number>::unroll_recursion(Vector &result, - unsigned int & index) const +template +Iterator +Tensor<0, dim, Number>::unroll_recursion(const Iterator current, + const Iterator end) const { Assert(dim != 0, ExcMessage("Cannot unroll an object of type Tensor<0,0,Number>")); - result[index] = value; - ++index; + Assert(current != end, ExcMessage("Cannot put value in end iterator")); + *current = value; + return current + 1; } @@ -1712,19 +1711,20 @@ Tensor::unroll(Vector &result) const AssertDimension(result.size(), (Utilities::fixed_power(dim))); - unsigned int index = 0; - unroll_recursion(result, index); + unroll_recursion(result.begin(), result.end()); } template -template -inline void -Tensor::unroll_recursion(Vector &result, - unsigned int & index) const +template +Iterator +Tensor::unroll_recursion(const Iterator current, + const Iterator end) const { + auto next = current; for (unsigned int i = 0; i < dim; ++i) - values[i].unroll_recursion(result, index); + next = values[i].unroll_recursion(next, end); + return next; }