diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 087f685ff6..b829c99ea5 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -184,6 +184,12 @@ public: // an out-of-range element returns false without any ill-effects inline const T& operator[](const label) const; + //- Return last element of UList. + inline T& last(); + + //- Return last element of UList. + inline const T& last() const; + //- Allow cast to a const List& inline operator const Foam::List&() const; diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 5c1df4be15..aa7d396f10 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -114,6 +114,20 @@ inline void Foam::UList::checkIndex(const label i) const } +template +inline T& Foam::UList::last() +{ + return this->operator[](this->size()-1); +} + + +template +inline const T& Foam::UList::last() const +{ + return this->operator[](this->size()-1); +} + + template inline const T* Foam::UList::cdata() const {