]> https://gitweb.dealii.org/ - dealii.git/commitdiff
VectorizedArrayIterator enable std::advance() 9675/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 18 Mar 2020 00:17:09 +0000 (01:17 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 19 Mar 2020 19:05:06 +0000 (20:05 +0100)
include/deal.II/base/vectorization.h
tests/base/vectorization_iterator_02.cc

index 3ff22504faf4f070d520728644976d5ec9358120..a6df94d4751d8dd2259888ee743e2b2d329b0775 100644 (file)
@@ -141,6 +141,7 @@ public:
    */
   const typename T::value_type &operator*() const
   {
+    AssertIndexRange(lane, T::size());
     return (*data)[lane];
   }
 
@@ -154,6 +155,7 @@ public:
                           typename T::value_type>::type &
   operator*()
   {
+    AssertIndexRange(lane, T::size());
     return (*data)[lane];
   }
 
@@ -165,16 +167,46 @@ public:
   VectorizedArrayIterator<T> &
   operator++()
   {
+    AssertIndexRange(lane + 1, T::size() + 1);
     lane++;
     return *this;
   }
 
+  /**
+   * This operator advances the iterator by @p offet lanes and returns a
+   * reference to <tt>*this</tt>.
+   */
+  VectorizedArrayIterator<T> &
+  operator+=(const unsigned int offset)
+  {
+    AssertIndexRange(lane + offset, T::size() + 1);
+    lane += offset;
+    return *this;
+  }
+
+  /**
+   * Prefix <tt>--</tt> operator: <tt>--iterator</tt>. This operator advances
+   * the iterator to the previous lane and returns a reference to
+   * <tt>*this</tt>.
+   */
+  VectorizedArrayIterator<T> &
+  operator--()
+  {
+    Assert(
+      lane > 0,
+      ExcMessage(
+        "You can't decrement an iterator that is already at the beginning of the range."));
+    --lane;
+    return *this;
+  }
+
   /**
    * Create new iterator, which is shifted by @p offset.
    */
   VectorizedArrayIterator<T>
-  operator+(const unsigned int &offset) const
+  operator+(const unsigned int offset) const
   {
+    AssertIndexRange(lane + offset, T::size() + 1);
     return VectorizedArrayIterator<T>(*data, lane + offset);
   }
 
index 5f695315009e51ac5af207fcf83cba316550020d..9f45b1a05918620145ff2cbd02cb50acb6fea3b2 100644 (file)
@@ -51,6 +51,10 @@ test_nonconst(VectorizedArray<Number> &vector)
                                   (VectorizedArray<Number>::n_array_elements -
                                    1)),
                   VectorizedArray<Number>::n_array_elements - 1);
+
+  auto it = vector.begin();
+  std::advance(it, VectorizedArray<Number>::n_array_elements - 1);
+  AssertDimension(*it, 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.