From 5514471c1517fd5e1bd0a507a31fd68a8489bd40 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 27 Apr 2017 01:30:50 +0200 Subject: [PATCH] BUG: FixedList '<' operator using a template parameter (fixes #458) - cannot use comparison of list sizes. Okay for UList, but not here. STYLE: - don't need two iterators for the '<' comparison, can just access internal storage directly --- applications/test/FixedList/Test-FixedList.C | 10 +++++++- .../containers/Lists/FixedList/FixedList.C | 25 +++++++------------ src/OpenFOAM/containers/Lists/UList/UList.C | 10 ++------ 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.C index 0a2c56a229..6e8210c825 100644 --- a/applications/test/FixedList/Test-FixedList.C +++ b/applications/test/FixedList/Test-FixedList.C @@ -33,7 +33,6 @@ See also \*---------------------------------------------------------------------------*/ #include "argList.H" -#include "IOstreams.H" #include "FixedList.H" #include "IFstream.H" #include "OFstream.H" @@ -64,6 +63,15 @@ int main(int argc, char *argv[]) Info<< "list2:" << list2 << " hash:" << FixedList::Hash<>()(list2) << endl; + // Using FixedList for content too + { + List> twolists{list, list2}; + Info<<"List of FixedList: " << flatOutput(twolists) << endl; + sort(twolists); + // outer-sort only + Info<<"sorted FixedList : " << flatOutput(twolists) << endl; + } + Info<< "list: " << list << nl << "list2: " << list2 << endl; list.swap(list2); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C index 6b919cf037..8a3b5d078b 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C @@ -70,31 +70,24 @@ bool Foam::FixedList::operator!=(const FixedList& a) const template bool Foam::FixedList::operator<(const FixedList& a) const { - for - ( - const_iterator vi = cbegin(), ai = a.cbegin(); - vi < cend() && ai < a.cend(); - vi++, ai++ - ) + const T* const __restrict__ ptr1 = this->begin(); + const T* const __restrict__ ptr2 = a.begin(); + + for (unsigned i=0; i *ai) + else if (ptr1[i] > ptr2[i]) { return false; } } - if (Size < a.Size) - { - return true; - } - else - { - return false; - } + // Contents look to be identical. + // The sizes are identical by definition (template parameter) + return false; } diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 320b22f68f..b36eae19e5 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -196,14 +196,8 @@ bool Foam::UList::operator<(const UList& a) const } } - if (this->size_ < a.size_) - { - return true; - } - else - { - return false; - } + // Contents look to be identical, or lists have different sizes + return (this->size_ < a.size_); }