From: Daniel Arndt Date: Mon, 19 Mar 2018 17:23:41 +0000 (+0100) Subject: Avoid deriving from std::iterator X-Git-Tag: v9.0.0-rc1~301^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83e8a6ae7da597bfbaf940118bfba13c1de90e7e;p=dealii.git Avoid deriving from std::iterator --- diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 908d3dfbb4..88e4cbcf07 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -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 + 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 + 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. diff --git a/include/deal.II/base/iterator_range.h b/include/deal.II/base/iterator_range.h index d67d504b28..9ad442f19d 100644 --- a/include/deal.II/base/iterator_range.h +++ b/include/deal.II/base/iterator_range.h @@ -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 + 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. diff --git a/include/deal.II/grid/tria_iterator.h b/include/deal.II/grid/tria_iterator.h index 330e855da0..94bb08bbd9 100644 --- a/include/deal.II/grid/tria_iterator.h +++ b/include/deal.II/grid/tria_iterator.h @@ -222,7 +222,7 @@ template class TriaActiveIterator; * @author documentation update Guido Kanschat, 2004 */ template -class TriaRawIterator : public std::iterator +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 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::iterator_category iterator_category; + typedef typename TriaRawIterator::value_type value_type; + typedef typename TriaRawIterator::pointer pointer; + typedef typename TriaRawIterator::reference reference; + typedef typename TriaRawIterator::difference_type difference_type; + /** * Exception */ @@ -842,6 +863,17 @@ public: TriaActiveIterator 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::iterator_category iterator_category; + typedef typename TriaIterator::value_type value_type; + typedef typename TriaIterator::pointer pointer; + typedef typename TriaIterator::reference reference; + typedef typename TriaIterator::difference_type difference_type; + /** * Exception */ diff --git a/include/deal.II/lac/block_vector_base.h b/include/deal.II/lac/block_vector_base.h index d1bbfd578b..5b2db60fd0 100644 --- a/include/deal.II/lac/block_vector_base.h +++ b/include/deal.II/lac/block_vector_base.h @@ -214,9 +214,7 @@ namespace internal * @author Wolfgang Bangerth, 2001 */ template - class Iterator : - public std::iterator::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; diff --git a/include/deal.II/particles/particle_iterator.h b/include/deal.II/particles/particle_iterator.h index d9aedcb2a5..f4b97ced17 100644 --- a/include/deal.II/particles/particle_iterator.h +++ b/include/deal.II/particles/particle_iterator.h @@ -31,7 +31,7 @@ namespace Particles * of the particle class and the particle container. */ template - class ParticleIterator: public std::iterator > + 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 value_type; + typedef std::ptrdiff_t difference_type; + typedef ParticleAccessor *pointer; + typedef ParticleAccessor &reference; + private: /** * The accessor to the actual particle. diff --git a/source/grid/tria.cc b/source/grid/tria.cc index cc8f7d4c67..99f37561ce 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -2972,7 +2972,7 @@ namespace internal { // use the rotate defined // in - 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 index 0000000000..5910aa7053 --- /dev/null +++ b/tests/bits/iterators_01.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include "../tests.h" + +int main () +{ + initlog(); + + typedef std::iterator_traits>>::iterator_category tria_raw_iterator_category; + typedef std::iterator_traits>>::iterator_category tria_iterator_category; + typedef std::iterator_traits>>::iterator_category tria_active_iterator_category; + + typedef std::iterator_traits>::iterator_category particle_category; + + typedef std::iterator_traits>::IteratorOverIterators>::iterator_category iterator_over_iterator_category; + + typedef std::iterator_traits, false>>::iterator_category block_vector_base_iterator_category; + + typedef std::iterator_traits::iterator_category intervall_iterator_category; + typedef std::iterator_traits::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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/bits/iterators_01.output @@ -0,0 +1,2 @@ + +DEAL::OK