From: Jean-Paul Pelteret Date: Fri, 3 May 2019 17:41:21 +0000 (+0200) Subject: WIP: Move IteratorOverIterators out of Iterator range class X-Git-Tag: v9.1.0-rc1~126^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7911%2Fhead;p=dealii.git WIP: Move IteratorOverIterators out of Iterator range class --- diff --git a/include/deal.II/base/iterator_range.h b/include/deal.II/base/iterator_range.h index a90266a88c..07960052e3 100644 --- a/include/deal.II/base/iterator_range.h +++ b/include/deal.II/base/iterator_range.h @@ -27,6 +27,12 @@ DEAL_II_NAMESPACE_OPEN +// Forward declarations +template +class IteratorOverIterators; + + + /** * A class that is used to denote a collection of iterators that can be * expressed in terms of a range of iterators characterized by a begin and an @@ -120,94 +126,9 @@ class IteratorRange { public: /** - * A class that implements the semantics of iterators over iterators as - * discussed in the design sections of the IteratorRange class. + * Typedef for the iterator type that iterates over other iterators. */ - class IteratorOverIterators - { - public: - /** - * Typedef the elements of the collection to give them a name that is more - * distinct. - */ - using BaseIterator = Iterator; - - /** - * Constructor. Initialize this iterator-over-iterator in such a way that - * it points to the given argument. - * - * @param iterator An iterator to which this object is supposed to point. - */ - IteratorOverIterators(const BaseIterator &iterator); - - /** - * Dereferencing operator. - * @return The iterator within the collection currently pointed to. - */ - const BaseIterator &operator*() const; - - /** - * Dereferencing operator. - * @return The iterator within the collection currently pointed to. - */ - const BaseIterator *operator->() const; - - /** - * Prefix increment operator. Move the current iterator to the next - * element of the collection and return the new value. - */ - IteratorOverIterators & - operator++(); - - /** - * Postfix increment operator. Move the current iterator to the next - * element of the collection, but return the previous value of the - * iterator. - */ - IteratorOverIterators - operator++(int); - - /** - * Comparison operator - * @param i_o_i Another iterator over iterators. - * @return Returns whether the current iterator points to a different - * object than the iterator represented by the argument. - */ - bool - operator!=(const IteratorOverIterators &i_o_i) const; - - /** - * Implicit conversion operator. - * - * @warning When you call this conversion operator (i.e., you convert this - * iterator-over-iterators to the iterator we are currently pointing to), - * you obtain a `const` reference to this underlying iterator. The only - * thing you can really do with this result is dereferencing itself: it - * presumably points to something useful, but since you don't know where - * the pointed to object lives, you shouldn't increment or decrement the - * iterator you get from this operator. As a consequence, the returned - * iterator is marked as `const`, as this should prevent you from doing - * anything other than dereference it. - */ - operator const BaseIterator &() const; - - /** - * Mark the class as forward iterator and declare some alias which are - * standard for iterators and are used by algorithms to enquire about the - * specifics of the iterators they work on. - */ - using iterator_category = std::forward_iterator_tag; - using value_type = Iterator; - using difference_type = typename Iterator::difference_type; - using pointer = Iterator *; - using reference = Iterator &; - - private: - /** - * The object this iterator currently points to. - */ - BaseIterator element_of_iterator_collection; - }; + using IteratorOverIterators = dealii::IteratorOverIterators; /** @@ -254,6 +175,99 @@ private: +/** + * A class that implements the semantics of iterators over iterators as + * discussed in the design sections of the IteratorRange class. + */ +template +class IteratorOverIterators +{ +public: + /** + * Typedef the elements of the collection to give them a name that is more + * distinct. + */ + using BaseIterator = Iterator; + + /** + * Constructor. Initialize this iterator-over-iterator in such a way that + * it points to the given argument. + * + * @param iterator An iterator to which this object is supposed to point. + */ + explicit IteratorOverIterators(const BaseIterator &iterator); + + /** + * Dereferencing operator. + * @return The iterator within the collection currently pointed to. + */ + const BaseIterator &operator*() const; + + /** + * Dereferencing operator. + * @return The iterator within the collection currently pointed to. + */ + const BaseIterator *operator->() const; + + /** + * Prefix increment operator. Move the current iterator to the next + * element of the collection and return the new value. + */ + IteratorOverIterators & + operator++(); + + /** + * Postfix increment operator. Move the current iterator to the next + * element of the collection, but return the previous value of the + * iterator. + */ + IteratorOverIterators + operator++(int); + + /** + * Comparison operator + * @param i_o_i Another iterator over iterators. + * @return Returns whether the current iterator points to a different + * object than the iterator represented by the argument. + */ + bool + operator!=(const IteratorOverIterators &i_o_i) const; + + /** + * Implicit conversion operator. + * + * @warning When you call this conversion operator (i.e., you convert this + * iterator-over-iterators to the iterator we are currently pointing to), + * you obtain a `const` reference to this underlying iterator. The only + * thing you can really do with this result is dereferencing itself: it + * presumably points to something useful, but since you don't know where + * the pointed to object lives, you shouldn't increment or decrement the + * iterator you get from this operator. As a consequence, the returned + * iterator is marked as `const`, as this should prevent you from doing + * anything other than dereference it. + */ + operator const BaseIterator &() const; + + /** + * Mark the class as forward iterator and declare some alias which are + * standard for iterators and are used by algorithms to enquire about the + * specifics of the iterators they work on. + */ + using iterator_category = std::forward_iterator_tag; + using value_type = Iterator; + using difference_type = typename Iterator::difference_type; + using pointer = Iterator *; + using reference = Iterator &; + +private: + /** + * The object this iterator currently points to. + */ + BaseIterator element_of_iterator_collection; +}; + + + /** * Create an object of type IteratorRange given the beginning and * end iterator. @@ -274,7 +288,7 @@ make_iterator_range(const BaseIterator & begin, template -inline IteratorRange::IteratorOverIterators::IteratorOverIterators( +inline IteratorOverIterators::IteratorOverIterators( const BaseIterator &iterator) : element_of_iterator_collection(iterator) {} @@ -282,9 +296,8 @@ inline IteratorRange::IteratorOverIterators::IteratorOverIterators( template -inline const typename IteratorRange< - Iterator>::IteratorOverIterators::BaseIterator & - IteratorRange::IteratorOverIterators::operator*() const +inline const typename IteratorOverIterators::BaseIterator & + IteratorOverIterators::operator*() const { return element_of_iterator_collection; } @@ -292,9 +305,8 @@ inline const typename IteratorRange< template -inline const typename IteratorRange< - Iterator>::IteratorOverIterators::BaseIterator * - IteratorRange::IteratorOverIterators::operator->() const +inline const typename IteratorOverIterators::BaseIterator * + IteratorOverIterators::operator->() const { return &element_of_iterator_collection; } @@ -302,8 +314,8 @@ inline const typename IteratorRange< template -inline typename IteratorRange::IteratorOverIterators & -IteratorRange::IteratorOverIterators::operator++() +inline IteratorOverIterators & +IteratorOverIterators::operator++() { ++element_of_iterator_collection; return *this; @@ -312,8 +324,8 @@ IteratorRange::IteratorOverIterators::operator++() template -inline typename IteratorRange::IteratorOverIterators -IteratorRange::IteratorOverIterators::operator++(int) +inline IteratorOverIterators +IteratorOverIterators::operator++(int) { const IteratorOverIterators old_value = *this; ++element_of_iterator_collection; @@ -324,7 +336,7 @@ IteratorRange::IteratorOverIterators::operator++(int) template inline bool -IteratorRange::IteratorOverIterators:: +IteratorOverIterators:: operator!=(const IteratorOverIterators &i_o_i) const { return element_of_iterator_collection != i_o_i.element_of_iterator_collection; @@ -333,8 +345,7 @@ operator!=(const IteratorOverIterators &i_o_i) const template -inline IteratorRange::IteratorOverIterators:: -operator const BaseIterator &() const +inline IteratorOverIterators::operator const BaseIterator &() const { return element_of_iterator_collection; } diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index c2fa346741..b675452ef6 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -1301,10 +1301,9 @@ namespace WorkStream typename ScratchData, typename CopyData> void - run(const typename IteratorRange::IteratorOverIterators &begin, - const typename IteratorRange< - typename identity::type>::IteratorOverIterators &end, - MainClass & main_object, + run(const IteratorOverIterators & begin, + const IteratorOverIterators::type> &end, + MainClass &main_object, void (MainClass::*worker)(const Iterator &, ScratchData &, CopyData &), void (MainClass::*copier)(const CopyData &), const ScratchData &sample_scratch_data, diff --git a/include/deal.II/meshworker/mesh_loop.h b/include/deal.II/meshworker/mesh_loop.h index d1c7ba3169..c34aefead1 100644 --- a/include/deal.II/meshworker/mesh_loop.h +++ b/include/deal.II/meshworker/mesh_loop.h @@ -64,17 +64,15 @@ namespace MeshWorker * TriaActiveIterator or a FilteredIterator as its base type. */ template - struct CellIteratorBaseType< - typename IteratorRange::IteratorOverIterators> + struct CellIteratorBaseType> { /** * Type definition for the cell iterator type. */ - using type = typename IteratorRange< - CellIteratorType>::IteratorOverIterators::BaseIterator; - - static_assert(std::is_same::value, - "Expected another type as the base iterator."); + // Since we can have filtered iterators and the like as template + // arguments, we recursivelyremove the template layers to retrieve the + // underlying iterator type. + using type = typename CellIteratorBaseType::type; }; /** @@ -95,26 +93,6 @@ namespace MeshWorker // remove the template layers to retrieve the underlying iterator type. using type = typename CellIteratorBaseType::type; }; - - /** - * A helper class to provide a type definition for the underlying cell - * iterator type. - * - * This specialization is for an IteratorRange that iterates over - * FilteredIterators. - */ - template - struct CellIteratorBaseType>::IteratorOverIterators> - { - /** - * Type definition for the cell iterator type. - */ - // Since we can have nested filtered iterators, we recursively - // remove the template layers to retrieve the underlying iterator type. - using type = - typename CellIteratorBaseType>::type; - }; } // namespace internal /**