diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 5f38f3f8fa..c77ba0ffb8 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -64,7 +64,12 @@ int main(int argc, char *argv[]) List list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; - List list2(IStringStream("((0 1 2) (3 4 5) (6 7 8))")()); + List list2 + { + vector(0, 1, 2), + vector(3, 4, 5), + vector(6, 7, 8) + }; Info<< "list2: " << list2 << endl; list1.append(list2); @@ -80,17 +85,32 @@ int main(int argc, char *argv[]) Info<< "list2: " << list2 << nl << "list3: " << list3 << endl; - List list4(IStringStream("((0 1 2) (3 4 5) (6 7 8))")()); - List list5(IStringStream("((5 3 1) (10 2 2) (8 1 0))")()); - Info<< "list4: " << list4 << nl - << "list5: " << list5 << endl; + List list4 + { + vector(0, 1, 2), + vector(3, 4, 5), + vector(6, 7, 8) + }; + Info<< "list4: " << list4 << endl; + + List list5 + { + vector(5, 3, 1), + vector(10, 2, 2), + vector(8, 1, 0) + }; + Info<< "list5: " << list5 << endl; + list4.swap(list5); Info<< "Swapped via the swap() method" << endl; Info<< "list4: " << list4 << nl << "list5: " << list5 << endl; + List list6(list4.begin(), list4.end()); + Info<< "list6: " << list6 << endl; + // Subset - const labelList map(IStringStream("2 (0 2)")()); + const labelList map{0, 2}; List subList3(list3, map); Info<< "Elements " << map << " out of " << list3 << " => " << subList3 << endl; diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 2f3b076678..8a5637845f 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -33,6 +33,43 @@ License #include "BiIndirectList.H" #include "contiguous.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +template +void Foam::List::CopyList(const List2& lst) +{ + if (this->size_) + { + this->v_ = new T[this->size_]; + + forAll(*this, i) + { + this->operator[](i) = lst[i]; + } + } +} + + +template +template +Foam::List::List(InputIterator first, InputIterator last, const label s) +: + UList(NULL, s) +{ + if (this->size_) + { + this->v_ = new T[this->size_]; + + InputIterator iter = first; + forAll(*this, i) + { + this->operator[](i) = *iter++; + } + } +} + + // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // template @@ -201,27 +238,27 @@ Foam::List::List(const UList& a, const labelUList& map) forAll(*this, i) { - this->v_[i] = a[map[i]]; + this->operator[](i) = a[map[i]]; } } } +template +template +Foam::List::List(InputIterator first, InputIterator last) +: + List(first, last, std::distance(first, last)) +{} + + template template Foam::List::List(const FixedList& lst) : UList(NULL, Size) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + CopyList(lst); } @@ -230,39 +267,15 @@ Foam::List::List(const PtrList& lst) : UList(NULL, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + CopyList(lst); } template Foam::List::List(const SLList& lst) : - UList(NULL, lst.size()) -{ - if (this->size_) - { - this->v_ = new T[this->size_]; - - label i = 0; - for - ( - typename SLList::const_iterator iter = lst.begin(); - iter != lst.end(); - ++iter - ) - { - this->operator[](i++) = iter(); - } - } -} + List(lst.first(), lst.last(), lst.size()) +{} template @@ -270,15 +283,7 @@ Foam::List::List(const UIndirectList& lst) : UList(NULL, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + CopyList(lst); } @@ -287,18 +292,17 @@ Foam::List::List(const BiIndirectList& lst) : UList(NULL, lst.size()) { - if (this->size_) - { - this->v_ = new T[this->size_]; - - forAll(*this, i) - { - this->operator[](i) = lst[i]; - } - } + CopyList(lst); } +template +Foam::List::List(std::initializer_list lst) +: + List(lst.begin(), lst.end()) +{} + + // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index be09d5c814..6996c8b2c3 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -43,6 +43,7 @@ SourceFiles #include "UList.H" #include "autoPtr.H" #include "Xfer.H" +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -82,6 +83,16 @@ class List : public UList { + // Private member functions + + //- Copy list of given type + template + void CopyList(const List2&); + + //- Construct given start and end iterators and number of elements + template + List(InputIterator first, InputIterator last, const label s); + protected: @@ -97,6 +108,7 @@ public: //- Return a null List inline static const List& null(); + // Constructors //- Null constructor @@ -114,7 +126,7 @@ public: //- Copy constructor List(const List&); - //- Copy constructor from list of another type + //- Copy constructor from list containing another type template explicit List(const List&); @@ -127,6 +139,10 @@ public: //- Construct as subset List(const UList&, const labelUList& mapAddressing); + //- Construct given start and end iterators + template + List(InputIterator first, InputIterator last); + //- Construct as copy of FixedList template explicit List(const FixedList&); @@ -143,6 +159,9 @@ public: //- Construct as copy of BiIndirectList explicit List(const BiIndirectList&); + //- Construct from an initializer list + List(std::initializer_list lst); + //- Construct from Istream List(Istream&); diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/ISAT/chemPointISAT/chemPointISAT.C b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/ISAT/chemPointISAT/chemPointISAT.C index 7ff29e3ad6..5144f2d242 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/ISAT/chemPointISAT/chemPointISAT.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/ISAT/chemPointISAT/chemPointISAT.C @@ -333,7 +333,7 @@ bool Foam::chemPointISAT::inEOA(const scalarField& phiq) bool isMechRedActive = chemistry_.mechRed()->active(); label dim = (isMechRedActive) ? nActiveSpecies_ : completeSpaceSize()-2; scalar epsTemp=0; - List propEps(completeSpaceSize(),0); + List propEps(completeSpaceSize(), scalar(0)); for (label i=0; i