From: Wolfgang Bangerth Date: Thu, 8 Jun 2023 21:07:34 +0000 (-0600) Subject: When available, use the C++20 iterator category. X-Git-Tag: v9.5.0-rc1~132^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15330%2Fhead;p=dealii.git When available, use the C++20 iterator category. --- diff --git a/include/deal.II/base/linear_index_iterator.h b/include/deal.II/base/linear_index_iterator.h index 2714c35f73..11ca01be9d 100644 --- a/include/deal.II/base/linear_index_iterator.h +++ b/include/deal.II/base/linear_index_iterator.h @@ -142,7 +142,11 @@ public: /** * Iterator category. */ +#ifdef DEAL_II_HAVE_CXX20 + using iterator_category = std::contiguous_iterator_tag; +#else using iterator_category = std::random_access_iterator_tag; +#endif /** * An alias for the type you get when you dereference an iterator of the diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index 69c9d5c773..957224abee 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -6052,9 +6052,13 @@ namespace std template struct iterator_traits> { +#ifdef DEAL_II_HAVE_CXX20 + using iterator_category = contiguous_iterator_tag; +#else using iterator_category = random_access_iterator_tag; - using value_type = typename T::value_type; - using difference_type = std::ptrdiff_t; +#endif + using value_type = typename T::value_type; + using difference_type = std::ptrdiff_t; }; } // namespace std diff --git a/include/deal.II/lac/block_vector_base.h b/include/deal.II/lac/block_vector_base.h index 01bff8f4ef..7e06727869 100644 --- a/include/deal.II/lac/block_vector_base.h +++ b/include/deal.II/lac/block_vector_base.h @@ -141,6 +141,13 @@ namespace internal * by algorithms to enquire about the specifics of the iterators they * work on. (Example: `std::next()`, which needs to know about a local * type named `difference_type`.) + * + * As for the iterator_category, C++20 has a more specialized + * contiguous_iterator_tag, but the elements of block vectors are + * not stored in a contiguous manner. They can be accessed in a + * random access order, though, with O(1) effort as long as we + * assume that the number of blocks of a vector is a constant + * (even though the *size* of the vector is not). */ using iterator_category = std::random_access_iterator_tag; using difference_type = std::ptrdiff_t;