From 659076c0fa603e8d0922c9b9a6f7ead40637ad3d Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 12 Aug 2016 10:01:41 +0100 Subject: [PATCH] LList, SLList: Added construction from and assignment to initializer_list SLList: now a C++11 template alias rather than a wrapper-class. --- applications/test/SLList/Test-SLList.C | 5 ++- .../LinkedLists/accessTypes/LList/LList.C | 36 +++++++++++++--- .../LinkedLists/accessTypes/LList/LList.H | 9 +++- .../LinkedLists/accessTypes/LList/LListIO.C | 11 ++--- .../containers/LinkedLists/user/SLList.H | 43 +++---------------- .../containers/Lists/FixedList/FixedList.H | 13 +++--- src/OpenFOAM/containers/Lists/List/List.H | 16 ++++--- .../ParticleCollector/ParticleCollector.C | 2 +- 8 files changed, 67 insertions(+), 68 deletions(-) diff --git a/applications/test/SLList/Test-SLList.C b/applications/test/SLList/Test-SLList.C index 5fa9dc8433..30baaa18e3 100644 --- a/applications/test/SLList/Test-SLList.C +++ b/applications/test/SLList/Test-SLList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,7 +39,8 @@ using namespace Foam; int main(int argc, char *argv[]) { - SLList myList; + SLList myList{2.1, 3.4}; + myList = {2.1, 3.4, 4.3}; for (int i = 0; i<10; i++) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C index ddecdcb0bd..7854cc9d84 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" #include "LList.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -33,9 +32,21 @@ Foam::LList::LList(const LList& lst) : LListBase() { - for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter) + for (const T& val : lst) { - this->append(iter()); + this->append(val); + } +} + + +template +Foam::LList::LList(std::initializer_list lst) +: + LListBase() +{ + for (const T& val : lst) + { + this->append(val); } } @@ -77,9 +88,21 @@ void Foam::LList::operator=(const LList& lst) { this->clear(); - for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter) + for (const T& val : lst) { - this->append(iter()); + this->append(val); + } +} + + +template +void Foam::LList::operator=(std::initializer_list lst) +{ + this->clear(); + + for (const T& val : lst) + { + this->append(val); } } @@ -88,5 +111,4 @@ void Foam::LList::operator=(const LList& lst) #include "LListIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H index fd1c3e0aef..cac481545e 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H @@ -37,7 +37,7 @@ SourceFiles #define LList_H #include "label.H" -#include "uLabel.H" +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -121,6 +121,9 @@ public: //- Construct as copy LList(const LList&); + //- Construct from an initializer list + LList(std::initializer_list); + //- Destructor ~LList(); @@ -206,8 +209,12 @@ public: // Member operators + //- Assignment operator void operator=(const LList&); + //- Assignment to an initializer list + void operator=(std::initializer_list); + // STL type definitions diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index c14ff358ea..a766ee85b9 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -144,14 +144,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const LList& lst) os << nl << token::BEGIN_LIST << nl; // Write contents - for - ( - typename LList::const_iterator iter = lst.begin(); - iter != lst.end(); - ++iter - ) + for (const T& val : lst) { - os << iter() << nl; + os << val << nl; } // Write end of contents diff --git a/src/OpenFOAM/containers/LinkedLists/user/SLList.H b/src/OpenFOAM/containers/LinkedLists/user/SLList.H index 6cb3d6ac62..8be3c5561e 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/SLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/SLList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,7 +21,7 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Class +Alias Foam::SLList Description @@ -39,42 +39,9 @@ Description namespace Foam { - -/*---------------------------------------------------------------------------*\ - Class SLList Declaration -\*---------------------------------------------------------------------------*/ - -template -class SLList -: - public LList -{ - -public: - - // Constructors - - //- Null construct - SLList() - {} - - //- Construct given initial T - explicit SLList(T a) - : - LList(a) - {} - - //- Construct from Istream - explicit SLList(Istream& is) - : - LList(is) - {} -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam + template + using SLList = LList; +} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 067894ad3d..f59582971e 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -61,8 +61,11 @@ template Ostream& operator<<(Ostream&, const FixedList&); template class UList; -template class SLList; +class SLListBase; +template class LList; +template +using SLList = LList; /*---------------------------------------------------------------------------*\ Class FixedList Declaration @@ -219,16 +222,16 @@ public: //- Return element of constant FixedList inline const T& operator[](const label) const; - //- Assignment from array operator. Takes linear time + //- Assignment to array operator. Takes linear time inline void operator=(const T v[Size]); - //- Assignment from UList operator. Takes linear time + //- Assignment to UList operator. Takes linear time inline void operator=(const UList&); - //- Assignment from SLList operator. Takes linear time + //- Assignment to SLList operator. Takes linear time inline void operator=(const SLList&); - //- Assignment from an initializer list. Takes linear time + //- Assignment to an initializer list. Takes linear time inline void operator=(std::initializer_list); //- Assignment of all entries to the given value diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index d93e5fe86d..448e4604ae 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -62,7 +62,11 @@ template Istream& operator>>(Istream&, List&); template class FixedList; template class PtrList; -template class SLList; + +class SLListBase; +template class LList; +template +using SLList = LList; template class DynamicList; @@ -247,22 +251,22 @@ public: // Member operators - //- Assignment from UList operator. Takes linear time + //- Assignment to UList operator. Takes linear time void operator=(const UList&); //- Assignment operator. Takes linear time void operator=(const List&); - //- Assignment from SLList operator. Takes linear time + //- Assignment to SLList operator. Takes linear time void operator=(const SLList&); - //- Assignment from UIndirectList operator. Takes linear time + //- Assignment to UIndirectList operator. Takes linear time void operator=(const UIndirectList&); - //- Assignment from BiIndirectList operator. Takes linear time + //- Assignment to BiIndirectList operator. Takes linear time void operator=(const BiIndirectList&); - //- Construct from an initializer list + //- Assignment to an initializer list void operator=(std::initializer_list); //- Assignment of all entries to the given value diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C index ce704984e5..066528fe3d 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C @@ -157,7 +157,7 @@ void Foam::ParticleCollector::initConcentricCircles() vector origin(this->coeffDict().lookup("origin")); - radius_ = this->coeffDict().lookup("radius"); + this->coeffDict().lookup("radius") >> radius_; nSector_ = readLabel(this->coeffDict().lookup("nSector")); label nS = nSector_;