]> https://gitweb.dealii.org/ - dealii.git/commitdiff
When available, use the C++20 iterator category. 15330/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 8 Jun 2023 21:07:34 +0000 (15:07 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 9 Jun 2023 15:29:02 +0000 (09:29 -0600)
include/deal.II/base/linear_index_iterator.h
include/deal.II/base/vectorization.h
include/deal.II/lac/block_vector_base.h

index 2714c35f739eb2fa2b3606cd4ab49d60b76efb80..11ca01be9de33b9461867ee71532c7534cf721a4 100644 (file)
@@ -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
index 69c9d5c77353968d419bfcfb7d16582cdc84e034..957224abee548c8c99221cd24772efcf15f4d536 100644 (file)
@@ -6052,9 +6052,13 @@ namespace std
   template <class T>
   struct iterator_traits<dealii::VectorizedArrayIterator<T>>
   {
+#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
index 01bff8f4efefe72fcc0f50b7ab4bde98289f4102..7e067278694f545613a2cca7ab2de2098ef99fd5 100644 (file)
@@ -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;

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.