From: Peter Munch Date: Wed, 18 Mar 2020 00:17:09 +0000 (+0100) Subject: VectorizedArrayIterator enable std::distance and add operator+ X-Git-Tag: v9.2.0-rc1~410^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c4216e81470308863ca7138baec54933a40552a;p=dealii.git VectorizedArrayIterator enable std::distance and add operator+ --- diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index d5f4b30d51..3ff22504fa 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -169,6 +169,25 @@ public: return *this; } + /** + * Create new iterator, which is shifted by @p offset. + */ + VectorizedArrayIterator + operator+(const unsigned int &offset) const + { + return VectorizedArrayIterator(*data, lane + offset); + } + + /** + * Compute distance between this iterator and iterator @p other. + */ + unsigned int + operator-(const VectorizedArrayIterator &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 + struct iterator_traits> + { + using iterator_category = random_access_iterator_tag; + using value_type = typename T::value_type; + using difference_type = unsigned int; + }; + } // namespace std #endif diff --git a/tests/base/vectorization_iterator_02.cc b/tests/base/vectorization_iterator_02.cc index c0ed5367a3..5f69531500 100644 --- a/tests/base/vectorization_iterator_02.cc +++ b/tests/base/vectorization_iterator_02.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// test for std::max_element on VectorizedArray +// test for std::max_element and std::distance on VectorizedArray #include @@ -27,6 +27,14 @@ test_const(const VectorizedArray &vector) { AssertDimension(*std::max_element(vector.begin(), vector.end()), VectorizedArray::n_array_elements - 1); + AssertDimension(std::distance(vector.begin(), + std::max_element(vector.begin(), vector.end())), + VectorizedArray::n_array_elements - 1); + AssertDimension(std::distance(vector.begin(), + vector.begin() + + (VectorizedArray::n_array_elements - + 1)), + VectorizedArray::n_array_elements - 1); } template @@ -35,6 +43,14 @@ test_nonconst(VectorizedArray &vector) { AssertDimension(*std::max_element(vector.begin(), vector.end()), VectorizedArray::n_array_elements - 1); + AssertDimension(std::distance(vector.begin(), + std::max_element(vector.begin(), vector.end())), + VectorizedArray::n_array_elements - 1); + AssertDimension(std::distance(vector.begin(), + vector.begin() + + (VectorizedArray::n_array_elements - + 1)), + VectorizedArray::n_array_elements - 1); } template