From: Peter Munch Date: Wed, 18 Mar 2020 00:17:09 +0000 (+0100) Subject: VectorizedArrayIterator enable std::advance() X-Git-Tag: v9.2.0-rc1~400^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc293a147a01608939a43c1e35bf91508c1a5989;p=dealii.git VectorizedArrayIterator enable std::advance() --- diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index 3ff22504fa..a6df94d475 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -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 & operator++() { + AssertIndexRange(lane + 1, T::size() + 1); lane++; return *this; } + /** + * This operator advances the iterator by @p offet lanes and returns a + * reference to *this. + */ + VectorizedArrayIterator & + operator+=(const unsigned int offset) + { + AssertIndexRange(lane + offset, T::size() + 1); + lane += offset; + return *this; + } + + /** + * Prefix -- operator: --iterator. This operator advances + * the iterator to the previous lane and returns a reference to + * *this. + */ + VectorizedArrayIterator & + 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 - operator+(const unsigned int &offset) const + operator+(const unsigned int offset) const { + AssertIndexRange(lane + offset, T::size() + 1); return VectorizedArrayIterator(*data, lane + offset); } diff --git a/tests/base/vectorization_iterator_02.cc b/tests/base/vectorization_iterator_02.cc index 5f69531500..9f45b1a059 100644 --- a/tests/base/vectorization_iterator_02.cc +++ b/tests/base/vectorization_iterator_02.cc @@ -51,6 +51,10 @@ test_nonconst(VectorizedArray &vector) (VectorizedArray::n_array_elements - 1)), VectorizedArray::n_array_elements - 1); + + auto it = vector.begin(); + std::advance(it, VectorizedArray::n_array_elements - 1); + AssertDimension(*it, VectorizedArray::n_array_elements - 1); } template