From 968f0bbd57b85f29ecaa69edd1eb2ddc7f5d7405 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 23 Nov 2009 12:55:20 +0000 Subject: [PATCH] added last() member function --- src/OpenFOAM/containers/Lists/UList/UList.H | 6 ++++++ src/OpenFOAM/containers/Lists/UList/UListI.H | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 087f685ff6c..b829c99ea5f 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<T>& inline operator const Foam::List<T>&() const; diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 5c1df4be15c..aa7d396f105 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<T>::checkIndex(const label i) const } +template<class T> +inline T& Foam::UList<T>::last() +{ + return this->operator[](this->size()-1); +} + + +template<class T> +inline const T& Foam::UList<T>::last() const +{ + return this->operator[](this->size()-1); +} + + template<class T> inline const T* Foam::UList<T>::cdata() const { -- GitLab