]> https://gitweb.dealii.org/ - dealii.git/commitdiff
VectorizedArrayIterator enable std::distance and add operator+ 9674/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 18 Mar 2020 00:17:09 +0000 (01:17 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 18 Mar 2020 01:16:33 +0000 (02:16 +0100)
include/deal.II/base/vectorization.h
tests/base/vectorization_iterator_02.cc

index d5f4b30d519358a81ea9e1dcf6c9d5ae6c4e3d79..3ff22504faf4f070d520728644976d5ec9358120 100644 (file)
@@ -169,6 +169,25 @@ public:
     return *this;
   }
 
+  /**
+   * Create new iterator, which is shifted by @p offset.
+   */
+  VectorizedArrayIterator<T>
+  operator+(const unsigned int &offset) const
+  {
+    return VectorizedArrayIterator<T>(*data, lane + offset);
+  }
+
+  /**
+   * Compute distance between this iterator and iterator @p other.
+   */
+  unsigned int
+  operator-(const VectorizedArrayIterator<T> &other) const
+  {
+    AssertIndexRange(other.lane, lane + 1);
+    return lane - other.lane;
+  }
+
 private:
   /**
    * Pointer to the actual VectorizedArray.
@@ -5439,6 +5458,19 @@ namespace std
     return x.get_min(y);
   }
 
+
+
+  /**
+   * Iterator traits for VectorizedArrayIterator.
+   */
+  template <class T>
+  struct iterator_traits<dealii::VectorizedArrayIterator<T>>
+  {
+    using iterator_category = random_access_iterator_tag;
+    using value_type        = typename T::value_type;
+    using difference_type   = unsigned int;
+  };
+
 } // namespace std
 
 #endif
index c0ed5367a3fe785a4e1481e7d2d7122d29cfdd66..5f695315009e51ac5af207fcf83cba316550020d 100644 (file)
@@ -14,7 +14,7 @@
 // ---------------------------------------------------------------------
 
 
-// test for std::max_element on VectorizedArray
+// test for std::max_element and std::distance on VectorizedArray
 
 #include <deal.II/base/vectorization.h>
 
@@ -27,6 +27,14 @@ test_const(const VectorizedArray<Number> &vector)
 {
   AssertDimension(*std::max_element(vector.begin(), vector.end()),
                   VectorizedArray<Number>::n_array_elements - 1);
+  AssertDimension(std::distance(vector.begin(),
+                                std::max_element(vector.begin(), vector.end())),
+                  VectorizedArray<Number>::n_array_elements - 1);
+  AssertDimension(std::distance(vector.begin(),
+                                vector.begin() +
+                                  (VectorizedArray<Number>::n_array_elements -
+                                   1)),
+                  VectorizedArray<Number>::n_array_elements - 1);
 }
 
 template <typename Number>
@@ -35,6 +43,14 @@ test_nonconst(VectorizedArray<Number> &vector)
 {
   AssertDimension(*std::max_element(vector.begin(), vector.end()),
                   VectorizedArray<Number>::n_array_elements - 1);
+  AssertDimension(std::distance(vector.begin(),
+                                std::max_element(vector.begin(), vector.end())),
+                  VectorizedArray<Number>::n_array_elements - 1);
+  AssertDimension(std::distance(vector.begin(),
+                                vector.begin() +
+                                  (VectorizedArray<Number>::n_array_elements -
+                                   1)),
+                  VectorizedArray<Number>::n_array_elements - 1);
 }
 
 template <typename Number>

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.