]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid deriving from std::iterator 6064/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 19 Mar 2018 17:23:41 +0000 (18:23 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 20 Mar 2018 04:32:03 +0000 (11:32 +0700)
include/deal.II/base/index_set.h
include/deal.II/base/iterator_range.h
include/deal.II/grid/tria_iterator.h
include/deal.II/lac/block_vector_base.h
include/deal.II/particles/particle_iterator.h
source/grid/tria.cc
tests/bits/iterators_01.cc [new file with mode: 0644]
tests/bits/iterators_01.output [new file with mode: 0644]

index 908d3dfbb4c40f075bb638eeb31cdc392671e62b..88e4cbcf07c164ca96e507f953e40d42cbf1bf76 100644 (file)
@@ -526,7 +526,7 @@ public:
    * Class that represents an iterator pointing to a contiguous interval
    * $[a,b[$ as returned by IndexSet::begin_interval().
    */
-  class IntervalIterator : public std::iterator<std::forward_iterator_tag,IntervalAccessor>
+  class IntervalIterator
   {
   public:
     /**
@@ -598,6 +598,17 @@ public:
      */
     int operator - (const IntervalIterator &p) const;
 
+    /**
+     * Mark the class as forward iterator and declare some typedefs which are
+     * standard for iterators and are used by algorithms to enquire about the
+     * specifics of the iterators they work on.
+     */
+    typedef std::forward_iterator_tag iterator_category;
+    typedef IntervalAccessor          value_type;
+    typedef std::ptrdiff_t            difference_type;
+    typedef IntervalAccessor         *pointer;
+    typedef IntervalAccessor         &reference;
+
   private:
     /**
      * Accessor that contains what IndexSet and interval we are pointing at.
@@ -609,7 +620,7 @@ public:
    * Class that represents an iterator pointing to a single element in the
    * IndexSet as returned by IndexSet::begin().
    */
-  class ElementIterator : public std::iterator<std::forward_iterator_tag,size_type>
+  class ElementIterator
   {
   public:
     /**
@@ -671,6 +682,17 @@ public:
      */
     std::ptrdiff_t operator - (const ElementIterator &p) const;
 
+    /**
+     * Mark the class as forward iterator and declare some typedefs which are
+     * standard for iterators and are used by algorithms to enquire about the
+     * specifics of the iterators they work on.
+     */
+    typedef std::forward_iterator_tag iterator_category;
+    typedef size_type                 value_type;
+    typedef std::ptrdiff_t            difference_type;
+    typedef size_type                *pointer;
+    typedef size_type                &reference;
+
   private:
     /**
      * Advance iterator by one.
index d67d504b2840cce17e87b35de81f831bdc233548..9ad442f19df462f656d0eb303454bcc597bc06e5 100644 (file)
@@ -121,8 +121,7 @@ public:
    * A class that implements the semantics of iterators over iterators as
    * discussed in the design sections of the IteratorRange class.
    */
-  class IteratorOverIterators : public std::iterator<std::forward_iterator_tag, Iterator,
-    typename Iterator::difference_type>
+  class IteratorOverIterators
   {
   public:
     /**
@@ -172,6 +171,17 @@ public:
      */
     bool operator != (const IteratorOverIterators &i_o_i);
 
+    /**
+     * Mark the class as forward iterator and declare some typedefs which are
+     * standard for iterators and are used by algorithms to enquire about the
+     * specifics of the iterators they work on.
+     */
+    typedef std::forward_iterator_tag          iterator_category;
+    typedef Iterator                           value_type;
+    typedef typename Iterator::difference_type difference_type;
+    typedef Iterator                          *pointer;
+    typedef Iterator                          &reference;
+
   private:
     /**
      * The object this iterator currently points to.
index 330e855da0b963a0092cae04b5ee59ff7f09a9d3..94bb08bbd96eb0e7f04e8afaa3d5217d89c774e0 100644 (file)
@@ -222,7 +222,7 @@ template <typename> class TriaActiveIterator;
  * @author documentation update Guido Kanschat, 2004
  */
 template <typename Accessor>
-class TriaRawIterator : public std::iterator<std::bidirectional_iterator_tag,Accessor>
+class TriaRawIterator
 {
 public:
   /**
@@ -464,6 +464,16 @@ public:
    */
   std::size_t memory_consumption () const;
 
+  /**
+   * Mark the class as bidirectional iterator and declare some typedefs which
+   * are standard for iterators and are used by algorithms to enquire about the
+   * specifics of the iterators they work on.
+   */
+  typedef std::bidirectional_iterator_tag iterator_category;
+  typedef Accessor                        value_type;
+  typedef int                             difference_type;
+  typedef Accessor                       *pointer;
+  typedef Accessor                       &reference;
 
   /**@name Exceptions*/
   /*@{*/
@@ -673,6 +683,17 @@ public:
   TriaIterator<Accessor> operator -- (int);
   /*@}*/
 
+  /**
+   * Declare some typedefs which are standard for iterators and are used
+   * by algorithms to enquire about the specifics of the iterators they
+   * work on.
+   */
+  typedef typename TriaRawIterator<Accessor>::iterator_category iterator_category;
+  typedef typename TriaRawIterator<Accessor>::value_type        value_type;
+  typedef typename TriaRawIterator<Accessor>::pointer           pointer;
+  typedef typename TriaRawIterator<Accessor>::reference         reference;
+  typedef typename TriaRawIterator<Accessor>::difference_type   difference_type;
+
   /**
    * Exception
    */
@@ -842,6 +863,17 @@ public:
   TriaActiveIterator<Accessor> operator -- (int);
   /*@}*/
 
+  /**
+   * Declare some typedefs which are standard for iterators and are used
+   * by algorithms to enquire about the specifics of the iterators they
+   * work on.
+   */
+  typedef typename TriaIterator<Accessor>::iterator_category iterator_category;
+  typedef typename TriaIterator<Accessor>::value_type        value_type;
+  typedef typename TriaIterator<Accessor>::pointer           pointer;
+  typedef typename TriaIterator<Accessor>::reference         reference;
+  typedef typename TriaIterator<Accessor>::difference_type   difference_type;
+
   /**
    * Exception
    */
index d1bbfd578b341a3f210c1162626dde4a1c76513b..5b2db60fd095eefd34e0ba8d2a710608136cb5d2 100644 (file)
@@ -214,9 +214,7 @@ namespace internal
      * @author Wolfgang Bangerth, 2001
      */
     template <class BlockVectorType, bool Constness>
-    class Iterator :
-      public std::iterator<std::random_access_iterator_tag,
-      typename Types<BlockVectorType,Constness>::value_type>
+    class Iterator
     {
     public:
       /**
@@ -238,7 +236,7 @@ namespace internal
        * by algorithms to enquire about the specifics of the iterators they
        * work on.
        */
-      typedef std::random_access_iterator_tag               iterator_type;
+      typedef std::random_access_iterator_tag               iterator_category;
       typedef std::ptrdiff_t                                difference_type;
       typedef typename BlockVectorType::reference           reference;
       typedef value_type                                   *pointer;
index d9aedcb2a540ed09eaf315ec072e832801882cf0..f4b97ced17c602e44d2891b40c091b8cbd161e05 100644 (file)
@@ -31,7 +31,7 @@ namespace Particles
    * of the particle class and the particle container.
    */
   template<int dim, int spacedim=dim>
-  class ParticleIterator: public std::iterator<std::bidirectional_iterator_tag,ParticleAccessor<dim,spacedim> >
+  class ParticleIterator
   {
   public:
     /**
@@ -113,6 +113,17 @@ namespace Particles
      */
     ParticleIterator operator -- (int);
 
+    /**
+     * Mark the class as bidirectional iterator and declare some typedefs which
+     * are standard for iterators and are used by algorithms to enquire about
+     * the specifics of the iterators they work on.
+     */
+    typedef std::bidirectional_iterator_tag iterator_category;
+    typedef ParticleAccessor<dim,spacedim>  value_type;
+    typedef std::ptrdiff_t                  difference_type;
+    typedef ParticleAccessor<dim,spacedim> *pointer;
+    typedef ParticleAccessor<dim,spacedim> &reference;
+
   private:
     /**
      * The accessor to the actual particle.
index cc8f7d4c67c1e1eca215db9a25822d0ad8d1b8ed..99f37561cedf62630a775bc23e5ac8f62e12a524 100644 (file)
@@ -2972,7 +2972,7 @@ namespace internal
               {
                 // use the rotate defined
                 // in <algorithms>
-                rotate(line_counterclock, line_counterclock+1, line_counterclock+4);
+                std::rotate(line_counterclock, line_counterclock+1, line_counterclock+4);
                 // update the quads with
                 // rotated lines (i runs in
                 // lexicographic ordering)
diff --git a/tests/bits/iterators_01.cc b/tests/bits/iterators_01.cc
new file mode 100644 (file)
index 0000000..5910aa7
--- /dev/null
@@ -0,0 +1,50 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Test that all the iterator types are defined.
+
+#include <deal.II/base/index_set.h>
+#include <deal.II/base/iterator_range.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/lac/block_vector_base.h>
+#include <deal.II/lac/block_vector.h>
+#include <deal.II/particles/particle_iterator.h>
+#include "../tests.h"
+
+int main ()
+{
+  initlog();
+
+  typedef std::iterator_traits<TriaRawIterator<TriaAccessor<2,2,2>>>::iterator_category    tria_raw_iterator_category;
+  typedef std::iterator_traits<TriaIterator<TriaAccessor<2,2,2>>>::iterator_category       tria_iterator_category;
+  typedef std::iterator_traits<TriaActiveIterator<TriaAccessor<2,2,2>>>::iterator_category tria_active_iterator_category;
+
+  typedef std::iterator_traits<Particles::ParticleIterator<2>>::iterator_category   particle_category;
+
+  typedef std::iterator_traits<IteratorRange<Particles::ParticleIterator<2>>::IteratorOverIterators>::iterator_category iterator_over_iterator_category;
+
+  typedef std::iterator_traits<internal::BlockVectorIterators::Iterator<BlockVector<double>, false>>::iterator_category block_vector_base_iterator_category;
+
+  typedef std::iterator_traits<IndexSet::IntervalIterator>::iterator_category intervall_iterator_category;
+  typedef std::iterator_traits<IndexSet::ElementIterator>::iterator_category   element_iterator_category;
+
+  deallog << "OK" << std::endl;
+}
+
+
+
diff --git a/tests/bits/iterators_01.output b/tests/bits/iterators_01.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.