diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index 4ed912500b..3fd58746fa 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,62 +54,6 @@ template class PtrList; // Forward declaration of friend functions and operators template class UPtrList; -template -inline typename UPtrList::iterator operator+ -( - const typename UPtrList::iterator&, - label -); - -template -inline typename UPtrList::iterator operator+ -( - label, - const typename UPtrList::iterator& -); - -template -inline typename UPtrList::iterator operator- -( - const typename UPtrList::iterator&, - label -); - -template -inline label operator- -( - const typename UPtrList::iterator&, - const typename UPtrList::iterator& -); - -template -inline typename UPtrList::const_iterator operator+ -( - const typename UPtrList::const_iterator&, - label -); - -template -inline typename UPtrList::const_iterator operator+ -( - label, - const typename UPtrList::const_iterator& -); - -template -inline typename UPtrList::const_iterator operator- -( - const typename UPtrList::const_iterator&, - label -); - -template -inline label operator- -( - const typename UPtrList::const_iterator&, - const typename UPtrList::const_iterator& -); - template Istream& operator>>(Istream&, UPtrList&); @@ -239,6 +183,7 @@ public: // Random access iterator for traversing UPtrList class iterator; + class const_iterator; friend class iterator; //- An STL iterator @@ -248,6 +193,8 @@ public: public: + friend class const_iterator; + //- Construct for a given UPtrList entry inline iterator(T**); @@ -260,27 +207,20 @@ public: inline T& operator()(); inline iterator operator++(); - inline iterator operator++(int); + inline iterator operator++(const int); inline iterator operator--(); - inline iterator operator--(int); + inline iterator operator--(const int); - inline iterator operator+=(label); + inline iterator operator+=(const label); + inline iterator operator-=(const label); - friend iterator operator+ (const iterator&, label); - friend iterator operator+ (label, const iterator&); + inline iterator operator+(const label) const; + inline iterator operator-(const label) const; - inline iterator operator-=(label); + inline label operator-(const iterator&) const; - friend iterator operator- (const iterator&, label); - - friend label operator- - ( - const iterator&, - const iterator& - ); - - inline T& operator[](label); + inline T& operator[](const label); inline bool operator<(const iterator&) const; inline bool operator>(const iterator&) const; @@ -323,39 +263,20 @@ public: inline Tref operator()(); inline const_iterator operator++(); - inline const_iterator operator++(int); + inline const_iterator operator++(const int); inline const_iterator operator--(); - inline const_iterator operator--(int); + inline const_iterator operator--(const int); - inline const_iterator operator+=(label); + inline const_iterator operator+=(const label); + inline const_iterator operator-=(const label); - friend const_iterator operator+ - ( - const const_iterator&, - label - ); - friend const_iterator operator+ - ( - label, - const const_iterator& - ); + inline const_iterator operator+(const label) const; + inline const_iterator operator-(const label) const; - inline const_iterator operator-=(label); + inline label operator-(const const_iterator&) const; - friend const_iterator operator- - ( - const const_iterator&, - label - ); - - friend label operator- - ( - const const_iterator&, - const const_iterator& - ); - - inline const T& operator[](label); + inline const T& operator[](const label); inline bool operator<(const const_iterator&) const; inline bool operator>(const const_iterator&) const; diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H index 191ae39da7..ae6cb38ab1 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -146,30 +146,35 @@ inline Foam::UPtrList::iterator::iterator(T** ptr) ptr_(ptr) {} + template inline bool Foam::UPtrList::iterator::operator==(const iterator& iter) const { return ptr_ == iter.ptr_; } + template inline bool Foam::UPtrList::iterator::operator!=(const iterator& iter) const { return ptr_ != iter.ptr_; } + template inline T& Foam::UPtrList::iterator::operator*() { return **ptr_; } + template inline T& Foam::UPtrList::iterator::operator()() { return operator*(); } + template inline typename Foam::UPtrList::iterator Foam::UPtrList::iterator::operator++() @@ -178,15 +183,17 @@ Foam::UPtrList::iterator::operator++() return *this; } + template inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator++(int) +Foam::UPtrList::iterator::operator++(const int) { iterator tmp = *this; ++ptr_; return tmp; } + template inline typename Foam::UPtrList::iterator Foam::UPtrList::iterator::operator--() @@ -195,95 +202,98 @@ Foam::UPtrList::iterator::operator--() return *this; } + template inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator--(int) +Foam::UPtrList::iterator::operator--(const int) { iterator tmp = *this; --ptr_; return tmp; } + template inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator+=(label n) +Foam::UPtrList::iterator::operator+=(const label n) { ptr_ += n; return *this; } -template -inline typename Foam::UPtrList::iterator -Foam::operator+(const typename UPtrList::iterator& iter, label n) -{ - typename UPtrList::iterator tmp = iter; - return tmp += n; -} template inline typename Foam::UPtrList::iterator -Foam::operator+(label n, const typename UPtrList::iterator& iter) -{ - typename UPtrList::iterator tmp = iter; - return tmp += n; -} - -template -inline typename Foam::UPtrList::iterator -Foam::UPtrList::iterator::operator-=(label n) +Foam::UPtrList::iterator::operator-=(const label n) { ptr_ -= n; return *this; } + template inline typename Foam::UPtrList::iterator -Foam::operator-(const typename UPtrList::iterator& iter, label n) +Foam::UPtrList::iterator::operator+(const label n) const { - typename UPtrList::iterator tmp = iter; + typename UPtrList::iterator tmp = *this; + return tmp += n; +} + + +template +inline typename Foam::UPtrList::iterator +Foam::UPtrList::iterator::operator-(const label n) const +{ + typename UPtrList::iterator tmp = *this; return tmp -= n; } -template -inline Foam::label Foam::operator- -( - const typename UPtrList::iterator& iter1, - const typename UPtrList::iterator& iter2 -) -{ - return (iter1.ptr_ - iter2.ptr_)/sizeof(T*); -} template -inline T& Foam::UPtrList::iterator::operator[](label n) +inline Foam::label Foam::UPtrList::iterator::operator- +( + const typename UPtrList::iterator& iter +) const +{ + return (ptr_ - iter.ptr_); +} + + +template +inline T& Foam::UPtrList::iterator::operator[](const label n) { return *(*this + n); } + template inline bool Foam::UPtrList::iterator::operator<(const iterator& iter) const { return ptr_ < iter.ptr_; } + template inline bool Foam::UPtrList::iterator::operator>(const iterator& iter) const { return ptr_ > iter.ptr_; } + template inline bool Foam::UPtrList::iterator::operator<=(const iterator& iter) const { return ptr_ <= iter.ptr_; } + template inline bool Foam::UPtrList::iterator::operator>=(const iterator& iter) const { return ptr_ >= iter.ptr_; } + template inline typename Foam::UPtrList::iterator Foam::UPtrList::begin() @@ -291,6 +301,7 @@ Foam::UPtrList::begin() return ptrs_.begin(); } + template inline typename Foam::UPtrList::iterator Foam::UPtrList::end() @@ -360,7 +371,7 @@ Foam::UPtrList::const_iterator::operator++() template inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator++(int) +Foam::UPtrList::const_iterator::operator++(const int) { const_iterator tmp = *this; ++ptr_; @@ -379,7 +390,7 @@ Foam::UPtrList::const_iterator::operator--() template inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator--(int) +Foam::UPtrList::const_iterator::operator--(const int) { const_iterator tmp = *this; --ptr_; @@ -389,7 +400,7 @@ Foam::UPtrList::const_iterator::operator--(int) template inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator+=(label n) +Foam::UPtrList::const_iterator::operator+=(const label n) { ptr_ += n; return *this; @@ -398,25 +409,7 @@ Foam::UPtrList::const_iterator::operator+=(label n) template inline typename Foam::UPtrList::const_iterator -Foam::operator+(const typename UPtrList::const_iterator& iter, label n) -{ - typename UPtrList::const_iterator tmp = iter; - return tmp += n; -} - - -template -inline typename Foam::UPtrList::const_iterator -Foam::operator+(label n, const typename UPtrList::const_iterator& iter) -{ - typename UPtrList::const_iterator tmp = iter; - return tmp += n; -} - - -template -inline typename Foam::UPtrList::const_iterator -Foam::UPtrList::const_iterator::operator-=(label n) +Foam::UPtrList::const_iterator::operator-=(const label n) { ptr_ -= n; return *this; @@ -425,26 +418,34 @@ Foam::UPtrList::const_iterator::operator-=(label n) template inline typename Foam::UPtrList::const_iterator -Foam::operator-(const typename UPtrList::const_iterator& iter, label n) +Foam::UPtrList::const_iterator::operator+(const label n) const { - typename UPtrList::const_iterator tmp = iter; + typename UPtrList::const_iterator tmp = *this; + return tmp += n; +} + + +template +inline typename Foam::UPtrList::const_iterator +Foam::UPtrList::const_iterator::operator-(const label n) const +{ + typename UPtrList::const_iterator tmp = *this; return tmp -= n; } template -inline Foam::label Foam::operator- +inline Foam::label Foam::UPtrList::const_iterator::operator- ( - const typename UPtrList::const_iterator& iter1, - const typename UPtrList::const_iterator& iter2 -) + const typename UPtrList::const_iterator& iter +) const { - return (iter1.ptr_ - iter2.ptr_)/sizeof(T*); + return (ptr_ - iter.ptr_); } template -inline const T& Foam::UPtrList::const_iterator::operator[](label n) +inline const T& Foam::UPtrList::const_iterator::operator[](const label n) { return *(*this + n); }