diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 5f71976aa9..02bdae8da0 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -148,9 +148,11 @@ public: //- Masking for all bits below the offset inline static unsigned int maskLower(unsigned offset); - // Forward declaration of iteratorBase + // Forward declaration of iterators class iteratorBase; + class iterator; + class const_iterator; // Constructors @@ -328,7 +330,7 @@ public: // Member Operators - //- Compare positions + //- Compare values (not positions) inline bool operator==(const iteratorBase&) const; inline bool operator!=(const iteratorBase&) const; @@ -355,7 +357,10 @@ public: public iteratorBase { - //- Should never violate const-ness! + //- Disallow copy constructor from const_iterator - violates const-ness! + iterator(const const_iterator&); + + //- Disallow assignment from const_iterator - violates const-ness! void operator=(const const_iterator&); public: @@ -375,6 +380,10 @@ public: // Member Operators + //- Compare positions (not values) + inline bool operator==(const iteratorBase&) const; + inline bool operator!=(const iteratorBase&) const; + //- Assign from iteratorBase, eg iter = packedlist[i] // An out-of-range iterator is assigned end() inline iterator& operator=(const iteratorBase&); @@ -420,17 +429,21 @@ public: //- Construct from iterator base, eg iter(packedlist[i]) // but also "const_iterator iter = packedlist[i];" - // An out-of-range iterator is assigned end() + // An out-of-range iterator is assigned cend() inline const_iterator(const iteratorBase&); //- Construct from base list and position index inline const_iterator(const PackedList*, const label); - //- Construct from non-const iterator + //- Construct from iterator inline const_iterator(const iterator&); // Member operators + //- Compare positions (not values) + inline bool operator==(const iteratorBase&) const; + inline bool operator!=(const iteratorBase&) const; + //- Assign from iteratorBase or derived // eg, iter = packedlist[i] or even iter = list.begin() inline const_iterator& operator=(const iteratorBase&); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 929688ef24..3b76234c2c 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -176,7 +176,7 @@ inline bool Foam::PackedList::iteratorBase::operator== const iteratorBase& iter ) const { - return this->index_ == iter.index_; + return this->get() == iter.get(); } @@ -186,7 +186,7 @@ inline bool Foam::PackedList::iteratorBase::operator!= const iteratorBase& iter ) const { - return this->index_ != iter.index_; + return this->get() != iter.get(); } @@ -311,6 +311,48 @@ inline Foam::PackedList::const_iterator::const_iterator {} +template +inline bool Foam::PackedList::iterator::operator== +( + const iteratorBase& iter +) const +{ + return this->index_ == iter.index_; +} + + +template +inline bool Foam::PackedList::iterator::operator!= +( + const iteratorBase& iter +) const +{ + return this->index_ != iter.index_; +} + + + +template +inline bool Foam::PackedList::const_iterator::operator== +( + const iteratorBase& iter +) const +{ + return this->index_ == iter.index_; +} + + +template +inline bool Foam::PackedList::const_iterator::operator!= +( + const iteratorBase& iter +) const +{ + return this->index_ != iter.index_; +} + + + template inline typename Foam::PackedList::iterator& Foam::PackedList::iterator::operator=(const iteratorBase& iter)