From afee861af99e32bbf4c9f7502890abc01a350d57 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 15 Feb 2023 11:12:13 +0100 Subject: [PATCH] DEFEATURE: remove PtrList random access iterators (#2702) - random access was unused. Retaining it would impede reimplementing iterators to only iterate across non-null items. --- applications/test/PtrList/Test-PtrList.C | 2 + .../containers/PtrLists/UPtrList/UPtrList.H | 58 +---- .../containers/PtrLists/UPtrList/UPtrListI.H | 202 ------------------ 3 files changed, 10 insertions(+), 252 deletions(-) diff --git a/applications/test/PtrList/Test-PtrList.C b/applications/test/PtrList/Test-PtrList.C index e6821e38d1..1ac282622a 100644 --- a/applications/test/PtrList/Test-PtrList.C +++ b/applications/test/PtrList/Test-PtrList.C @@ -562,6 +562,7 @@ int main(int argc, char *argv[]) << "ulist2: " << ulist2 << nl; // Test iterator random access + #if (OPENFOAM <= 2212) { auto iter1 = ulist1.begin(); auto iter2 = iter1 + 3; @@ -576,6 +577,7 @@ int main(int argc, char *argv[]) Info<< "*" << (*iter1).value() << nl; Info<< "()" << iter1().value() << nl; } + #endif PtrList planes; planes.emplace_back(vector::one, vector::one); diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index 675fd2a18c..8be5fc8855 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -106,10 +106,10 @@ public: //- A const reference to the value_type typedef const T& const_reference; - //- Random-access iterator with non-const access + //- Forward iterator with non-const access class iterator; - //- Random-access iterator with const access + //- Forward iterator with const access class const_iterator; @@ -346,7 +346,7 @@ public: // Iterators - //- Random-access iterator with non-const access + //- Forward iterator with non-const access class iterator { // Pointer to parent @@ -354,7 +354,7 @@ public: public: - using iterator_category = std::random_access_iterator_tag; + using iterator_category = std::forward_iterator_tag; using value_type = T; using difference_type = label; using pointer = T*; @@ -374,37 +374,16 @@ public: inline pointer operator->() const; inline reference operator*() const; - reference operator()() const { return this->operator*(); } - inline reference operator[](difference_type n) const; - - // Forward iteration + // Forward Iteration inline iterator& operator++() noexcept; inline iterator operator++(int) noexcept; - inline iterator& operator--() noexcept; - inline iterator operator--(int) noexcept; - - // Random-access - inline iterator& operator+=(difference_type n) noexcept; - inline iterator& operator-=(difference_type n) noexcept; - inline iterator operator+(difference_type n) const noexcept; - inline iterator operator-(difference_type n) const noexcept; - - inline difference_type operator-(const iterator& iter) - const noexcept; - inline bool operator==(const iterator& iter) const noexcept; inline bool operator!=(const iterator& iter) const noexcept; - - inline bool operator<(const iterator& iter) const noexcept; - inline bool operator>(const iterator& iter) const noexcept; - - inline bool operator<=(const iterator& iter) const noexcept; - inline bool operator>=(const iterator& iter) const noexcept; }; - //- Random-access iterator with const access + //- Forward iterator with const access class const_iterator { // Pointer to parent @@ -412,7 +391,7 @@ public: public: - using iterator_category = std::random_access_iterator_tag; + using iterator_category = std::forward_iterator_tag; using value_type = const T; using difference_type = label; using pointer = const T*; @@ -434,33 +413,12 @@ public: inline pointer operator->() const; inline reference operator*() const; - reference operator()() const { return this->operator*(); } - inline reference operator[](difference_type n) const; - - // Forward iteration + // Forward Iteration inline const_iterator& operator++() noexcept; inline const_iterator operator++(int) noexcept; - inline const_iterator& operator--() noexcept; - inline const_iterator operator--(int) noexcept; - - // Random-access - inline const_iterator& operator+=(difference_type n) noexcept; - inline const_iterator& operator-=(difference_type n) noexcept; - inline const_iterator operator+(difference_type n) const noexcept; - inline const_iterator operator-(difference_type n) const noexcept; - - inline difference_type operator-(const const_iterator& iter) - const noexcept; - inline bool operator==(const const_iterator& iter) const noexcept; inline bool operator!=(const const_iterator& iter) const noexcept; - - inline bool operator<(const const_iterator& iter) const noexcept; - inline bool operator>(const const_iterator& iter) const noexcept; - - inline bool operator<=(const const_iterator& iter) const noexcept; - inline bool operator>=(const const_iterator& iter) const noexcept; }; diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index d646b572cc..eacbe831d0 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -316,12 +316,6 @@ inline T& Foam::UPtrList::iterator::operator*() const } -template -inline T& Foam::UPtrList::iterator::operator[](label n) const -{ - return **(ptr_ + n); -} - template inline typename Foam::UPtrList::iterator& Foam::UPtrList::iterator::operator++() noexcept @@ -341,68 +335,6 @@ Foam::UPtrList::iterator::operator++(int) noexcept } -template -inline typename Foam::UPtrList::iterator& -Foam::UPtrList::iterator::operator--() noexcept -{ - --ptr_; - return *this; -} - - -template -inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator--(int) noexcept -{ - iterator iter(*this); - --ptr_; - return iter; -} - - -template -inline typename Foam::UPtrList::iterator& -Foam::UPtrList::iterator::operator+=(label n) noexcept -{ - ptr_ += n; - return *this; -} - - -template -inline typename Foam::UPtrList::iterator& -Foam::UPtrList::iterator::operator-=(label n) noexcept -{ - ptr_ -= n; - return *this; -} - - -template -inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator+(label n) const noexcept -{ - return iterator(ptr_ + n); -} - - -template -inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator-(label n) const noexcept -{ - return iterator(ptr_ - n); -} - - -template -inline Foam::label -Foam::UPtrList::iterator:: -operator-(const iterator& iter) const noexcept -{ - return (ptr_ - iter.ptr_); -} - - template inline bool Foam::UPtrList::iterator:: operator==(const iterator& iter) const noexcept @@ -419,38 +351,6 @@ operator!=(const iterator& iter) const noexcept } -template -inline bool Foam::UPtrList::iterator:: -operator<(const iterator& iter) const noexcept -{ - return ptr_ < iter.ptr_; -} - - -template -inline bool Foam::UPtrList::iterator:: -operator>(const iterator& iter) const noexcept -{ - return ptr_ > iter.ptr_; -} - - -template -inline bool Foam::UPtrList::iterator:: -operator<=(const iterator& iter) const noexcept -{ - return ptr_ <= iter.ptr_; -} - - -template -inline bool Foam::UPtrList::iterator:: -operator>=(const iterator& iter) const noexcept -{ - return ptr_ >= iter.ptr_; -} - - // * * * * * * * * * * * * * * * const_iterator * * * * * * * * * * * * * * // template @@ -483,14 +383,6 @@ inline const T& Foam::UPtrList::const_iterator::operator*() const } -template -inline const T& -Foam::UPtrList::const_iterator::operator[](label n) const -{ - return **(ptr_ + n); -} - - template inline typename Foam::UPtrList::const_iterator& Foam::UPtrList::const_iterator::operator++() noexcept @@ -510,68 +402,6 @@ Foam::UPtrList::const_iterator::operator++(int) noexcept } -template -inline typename Foam::UPtrList::const_iterator& -Foam::UPtrList::const_iterator::operator--() noexcept -{ - --ptr_; - return *this; -} - - -template -inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator--(int) noexcept -{ - const_iterator iter(*this); - --ptr_; - return iter; -} - - -template -inline typename Foam::UPtrList::const_iterator& -Foam::UPtrList::const_iterator::operator+=(label n) noexcept -{ - ptr_ += n; - return *this; -} - - -template -inline typename Foam::UPtrList::const_iterator& -Foam::UPtrList::const_iterator::operator-=(label n) noexcept -{ - ptr_ -= n; - return *this; -} - - -template -inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator+(label n) const noexcept -{ - return const_iterator(ptr_ + n); -} - - -template -inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator-(label n) const noexcept -{ - return const_iterator(ptr_ - n); -} - - -template -inline Foam::label -Foam::UPtrList::const_iterator:: -operator-(const const_iterator& iter) const noexcept -{ - return (ptr_ - iter.ptr_); -} - - template inline bool Foam::UPtrList::const_iterator:: operator==(const const_iterator& iter) const noexcept @@ -588,38 +418,6 @@ operator!=(const const_iterator& iter) const noexcept } -template -inline bool Foam::UPtrList::const_iterator:: -operator<(const const_iterator& iter) const noexcept -{ - return ptr_ < iter.ptr_; -} - - -template -inline bool Foam::UPtrList::const_iterator:: -operator>(const const_iterator& iter) const noexcept -{ - return ptr_ > iter.ptr_; -} - - -template -inline bool Foam::UPtrList::const_iterator:: -operator<=(const const_iterator& iter) const noexcept -{ - return ptr_ <= iter.ptr_; -} - - -template -inline bool Foam::UPtrList::const_iterator:: -operator>=(const const_iterator& iter) const noexcept -{ - return ptr_ >= iter.ptr_; -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template