diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index be198f8ffa..6c03173401 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,14 +59,14 @@ class DynamicList; template Ostream& operator<< ( - Ostream&, - const DynamicList& + Ostream& os, + const DynamicList& lst ); template Istream& operator>> ( - Istream&, - DynamicList& + Istream& is, + DynamicList& lst ); @@ -105,29 +105,37 @@ public: inline DynamicList(); //- Construct given size. - explicit inline DynamicList(const label); + explicit inline DynamicList(const label nElem); //- Construct with given size and value for all elements. - inline DynamicList(const label, const T&); + inline DynamicList(const label nElem, const T& a); //- Construct copy. - inline DynamicList(const DynamicList&); + inline DynamicList + ( + const DynamicList& lst + ); //- Construct from UList. Size set to UList size. // Also constructs from DynamicList with different sizing parameters. - explicit inline DynamicList(const UList&); + explicit inline DynamicList(const UList& lst); + + //- Construct given begin/end iterators. + // Uses std::distance to determine the size. + template + inline DynamicList(InputIterator begIter, InputIterator endIter); //- Construct from an initializer list. Size set to list size. - explicit inline DynamicList(std::initializer_list); + explicit inline DynamicList(std::initializer_list lst); //- Construct from UIndirectList. Size set to UIndirectList size. - explicit inline DynamicList(const UIndirectList&); + explicit inline DynamicList(const UIndirectList& lst); //- Construct by transferring the parameter contents - explicit inline DynamicList(const Xfer>&); + explicit inline DynamicList(const Xfer>& lst); //- Construct from Istream. Size set to size of list read. - explicit DynamicList(Istream&); + explicit DynamicList(Istream& is); // Member Functions @@ -143,31 +151,31 @@ public: // The addressed size will be truncated if needed to fit, but will // remain otherwise untouched. // Use this or reserve() in combination with append(). - inline void setCapacity(const label); + inline void setCapacity(const label nElem); //- Alter the addressed list size. // New space will be allocated if required. // Use this to resize the list prior to using the operator[] for // setting values (as per List usage). - inline void setSize(const label); + inline void setSize(const label nElem); //- Alter the addressed list size and fill new space with a // constant. - inline void setSize(const label, const T&); + inline void setSize(const label nElem, const T& t); //- Alter the addressed list size. // New space will be allocated if required. // Use this to resize the list prior to using the operator[] for // setting values (as per List usage). - inline void resize(const label); + inline void resize(const label nElem); //- Alter the addressed list size and fill new space with a // constant. - inline void resize(const label, const T&); + inline void resize(const label nElem, const T& t); //- Reserve allocation space for at least this size. // Never shrinks the allocated size, use setCapacity() for that. - inline void reserve(const label); + inline void reserve(const label nElem); //- Clear the addressed list, i.e. set the size to zero. // Allocated size does not change @@ -181,10 +189,13 @@ public: inline DynamicList& shrink(); //- Transfer contents of the argument List into this. - inline void transfer(List&); + inline void transfer(List& lst); //- Transfer contents of the argument DynamicList into this. - inline void transfer(DynamicList&); + inline void transfer + ( + DynamicList& lst + ); //- Transfer contents to the Xfer container as a plain List inline Xfer> xfer(); @@ -195,25 +206,25 @@ public: //- Append an element at the end of the list inline DynamicList& append ( - const T& + const T& t ); //- Append a List at the end of this list inline DynamicList& append ( - const UList& + const UList& lst ); //- Append an initializer list at the end of this list. inline DynamicList& append ( - std::initializer_list + std::initializer_list lst ); //- Append a UIndirectList at the end of this list inline DynamicList& append ( - const UIndirectList& + const UIndirectList& lst ); //- Remove and return the top element @@ -221,32 +232,35 @@ public: //- Return non-const access to an element, resizing list if // necessary - inline T& operator()(const label); + inline T& operator()(const label elemI); //- Assignment of all addressed entries to the given value - inline void operator=(const T&); + inline void operator=(const T& t); //- Assignment to DynamicList inline void operator= ( - const DynamicList& + const DynamicList& lst ); //- Assignment to UList - inline void operator=(const UList&); + inline void operator=(const UList& lst); //- Assignment from initializer list - inline void operator=(std::initializer_list); + inline void operator=(std::initializer_list lst); //- Assignment to UIndirectList - inline void operator=(const UIndirectList&); + inline void operator=(const UIndirectList& lst); // STL member functions //- Erase an element, move the remaining elements to fill the gap // and resize the List - typename UList::iterator erase(typename UList::iterator); + typename UList::iterator erase + ( + typename UList::iterator curIter + ); // IOstream operators @@ -254,15 +268,15 @@ public: // Write DynamicList to Ostream. friend Ostream& operator<< ( - Ostream&, - const DynamicList& + Ostream& os, + const DynamicList& lst ); //- Read from Istream, discarding contents of existing DynamicList. friend Istream& operator>> ( - Istream&, - DynamicList& + Istream& is, + DynamicList& lst ); }; diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 82f28f5cb5..e6ba973b48 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -80,6 +80,19 @@ inline Foam::DynamicList::DynamicList {} +template +template +inline Foam::DynamicList::DynamicList +( + InputIterator begIter, + InputIterator endIter +) +: + List(begIter, endIter), + capacity_(this->size()) +{} + + template inline Foam::DynamicList::DynamicList ( diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index bdf75aa401..dce2cad0c6 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -128,11 +128,12 @@ public: explicit inline FixedList(const T& t); //- Construct from C-array - explicit inline FixedList(const T v[Size]); + explicit inline FixedList(const T lst[Size]); - //- Construct given start and end iterators + //- Construct given begin/end iterators + // Uses std::distance when verifying the size. template - inline FixedList(InputIterator first, InputIterator last); + inline FixedList(InputIterator begIter, InputIterator endIter); //- Construct from an initializer list inline FixedList(std::initializer_list lst); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 2f97b93169..1df4fb958a 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -37,7 +37,7 @@ inline Foam::FixedList::FixedList() template inline Foam::FixedList::FixedList(const T& t) { - for (unsigned i=0; i::FixedList(const T& t) template -inline Foam::FixedList::FixedList(const T v[Size]) +inline Foam::FixedList::FixedList(const T lst[Size]) { - for (unsigned i=0; i template Foam::FixedList::FixedList ( - InputIterator first, - InputIterator last + InputIterator begIter, + InputIterator endIter ) { - checkSize(std::distance(first, last)); + checkSize(std::distance(begIter, endIter)); - InputIterator iter = first; - for (unsigned i=0; i inline Foam::FixedList::FixedList(std::initializer_list lst) -: - FixedList(lst.begin(), lst.end()) -{} +{ + checkSize(lst.size()); + + auto iter = lst.begin(); + for (unsigned i=0; i @@ -84,7 +92,7 @@ inline Foam::FixedList::FixedList(const UList& lst) { checkSize(lst.size()); - for (unsigned i=0; i::FixedList(const SLList& lst) checkSize(lst.size()); typename SLList::const_iterator iter = lst.begin(); - for (unsigned i=0; i::FixedList(const SLList& lst) template inline Foam::FixedList::FixedList(const FixedList& lst) { - for (unsigned i=0; i::setSize(const label s) template inline void Foam::FixedList::transfer(const FixedList& lst) { - for (unsigned i=0; i::operator[](const label i) const template inline void Foam::FixedList::operator=(const T lst[Size]) { - for (unsigned i=0; i::operator=(const UList& lst) { checkSize(lst.size()); - for (unsigned i=0; i::operator=(const SLList& lst) checkSize(lst.size()); typename SLList::const_iterator iter = lst.begin(); - for (unsigned i=0; i::operator=(std::initializer_list lst) { checkSize(lst.size()); - typename std::initializer_list::iterator iter = lst.begin(); - for (unsigned i=0; i inline void Foam::FixedList::operator=(const T& t) { - for (unsigned i=0; i::Hash::operator() // Hash incrementally unsigned val = seed; - for (unsigned i=0; i::List(List& a, bool reuse) if (reuse) { this->v_ = a.v_; - a.v_ = 0; + a.v_ = nullptr; a.size_ = 0; } else if (this->size_) @@ -186,19 +186,19 @@ Foam::List::List(List& a, bool reuse) template -Foam::List::List(const UList& a, const labelUList& map) +Foam::List::List(const UList& a, const labelUList& mapAddressing) : - UList(nullptr, map.size()) + UList(nullptr, mapAddressing.size()) { if (this->size_) { - // Note:cannot use List_ELEM since third argument has to be index. + // Note: cannot use List_ELEM since third argument has to be index. alloc(); forAll(*this, i) { - this->operator[](i) = a[map[i]]; + this->operator[](i) = a[mapAddressing[i]]; } } } @@ -206,9 +206,9 @@ Foam::List::List(const UList& a, const labelUList& map) template template -Foam::List::List(InputIterator first, InputIterator last) +Foam::List::List(InputIterator begIter, InputIterator endIter) : - List(first, last, std::distance(first, last)) + List(begIter, endIter, std::distance(begIter, endIter)) {} @@ -231,6 +231,8 @@ Foam::List::List(const PtrList& lst) } +// Note: using first/last is not entirely accurate. +// But since the list size is correct, last() is actually ignored. template Foam::List::List(const SLList& lst) : @@ -259,7 +261,7 @@ Foam::List::List(const BiIndirectList& lst) template Foam::List::List(std::initializer_list lst) : - List(lst.begin(), lst.end()) + List(lst.begin(), lst.end(), lst.size()) {} @@ -326,7 +328,7 @@ void Foam::List::setSize(const label newSize) template void Foam::List::setSize(const label newSize, const T& a) { - label oldSize = label(this->size_); + const label oldSize = label(this->size_); this->setSize(newSize); if (newSize > oldSize) @@ -346,7 +348,7 @@ void Foam::List::transfer(List& a) this->v_ = a.v_; a.size_ = 0; - a.v_ = 0; + a.v_ = nullptr; } @@ -419,14 +421,9 @@ void Foam::List::operator=(const SLList& lst) if (this->size_) { label i = 0; - for - ( - typename SLList::const_iterator iter = lst.begin(); - iter != lst.end(); - ++iter - ) + for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) { - this->operator[](i++) = iter(); + this->operator[](i++) = *iter; } } } @@ -453,10 +450,11 @@ void Foam::List::operator=(std::initializer_list lst) { reAlloc(lst.size()); - typename std::initializer_list::iterator iter = lst.begin(); + auto iter = lst.begin(); forAll(*this, i) { - this->operator[](i) = *iter++; + this->operator[](i) = *iter; + ++iter; } } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index fdb4559bf7..c8e3219d99 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -58,7 +58,7 @@ class Ostream; // Forward declaration of friend functions and operators template class List; -template Istream& operator>>(Istream&, List&); +template Istream& operator>>(Istream& is, List& L); template class FixedList; template class PtrList; @@ -95,22 +95,28 @@ class List //- Copy list of given type template - inline void copyList(const List2&); + inline void copyList(const List2& lst); //- Allocate storage and copy list of given type template - inline void allocCopyList(const List2&); + inline void allocCopyList(const List2& lst); - //- Construct given start and end iterators and number of elements + //- Construct given begin/end iterators and number of elements + // Since the size is provided, the end iterator is actually ignored. template - inline List(InputIterator first, InputIterator last, const label s); + inline List + ( + InputIterator begIter, + InputIterator endIter, + const label s + ); protected: //- Override size to be inconsistent with allocated storage. // Use with care - inline void size(const label); + inline void size(const label n); public: @@ -127,55 +133,56 @@ public: inline List(); //- Construct with given size - explicit List(const label); + explicit List(const label s); //- Construct with given size and value for all elements - List(const label, const T&); + List(const label s, const T& a); //- Construct with given size initializing all elements to zero - List(const label, const zero); + List(const label s, const zero); //- Copy constructor - List(const List&); + List(const List& a); //- Copy constructor from list containing another type template - explicit List(const List&); + explicit List(const List& a); //- Construct by transferring the parameter contents - List(const Xfer>&); + List(const Xfer>& lst); //- Construct as copy or re-use as specified - List(List&, bool reuse); + List(List& a, bool reuse); //- Construct as subset - List(const UList&, const labelUList& mapAddressing); + List(const UList& a, const labelUList& mapAddressing); - //- Construct given start and end iterators + //- Construct given begin/end iterators. + // Uses std::distance to determine the size. template - List(InputIterator first, InputIterator last); + List(InputIterator begIter, InputIterator endIter); //- Construct as copy of FixedList template - explicit List(const FixedList&); + explicit List(const FixedList& lst); //- Construct as copy of PtrList - explicit List(const PtrList&); + explicit List(const PtrList& lst); //- Construct as copy of SLList - explicit List(const SLList&); + explicit List(const SLList& lst); //- Construct as copy of UIndirectList - explicit List(const UIndirectList&); + explicit List(const UIndirectList& lst); //- Construct as copy of BiIndirectList - explicit List(const BiIndirectList&); + explicit List(const BiIndirectList& lst); //- Construct from an initializer list - List(std::initializer_list); + List(std::initializer_list lst); //- Construct from Istream - List(Istream&); + List(Istream& is); //- Clone inline autoPtr> clone() const; @@ -200,47 +207,48 @@ public: // Edit //- Alias for setSize(const label) - inline void resize(const label); + inline void resize(const label newSize); //- Alias for setSize(const label, const T&) - inline void resize(const label, const T&); + inline void resize(const label newSize, const T& a); //- Reset size of List - void setSize(const label); + void setSize(const label newSize); //- Reset size of List and value for new elements - void setSize(const label, const T&); + void setSize(const label newSize, const T& a); //- Clear the list, i.e. set size to zero inline void clear(); //- Append an element at the end of the list - inline void append(const T&); + inline void append(const T& t); //- Append a List at the end of this list - inline void append(const UList&); + inline void append(const UList& lst); //- Append a UIndirectList at the end of this list - inline void append(const UIndirectList&); + inline void append(const UIndirectList& lst); //- Transfer the contents of the argument List into this list // and annul the argument list - void transfer(List&); + void transfer(List& a); //- Transfer the contents of the argument List into this list // and annul the argument list template - void transfer(DynamicList&); + void transfer(DynamicList& a); //- Transfer the contents of the argument List into this list // and annul the argument list - void transfer(SortableList&); + void transfer(SortableList& a); //- Transfer contents to the Xfer container inline Xfer> xfer(); - //- Return subscript-checked element of UList - inline T& newElmt(const label); + //- Return subscript-checked element of UList. + // Resize list if required. + inline T& newElmt(const label i); //- Disallow implicit shallowCopy @@ -250,25 +258,25 @@ public: // Member operators //- Assignment to UList operator. Takes linear time - void operator=(const UList&); + void operator=(const UList& a); //- Assignment operator. Takes linear time - void operator=(const List&); + void operator=(const List& a); //- Assignment to SLList operator. Takes linear time - void operator=(const SLList&); + void operator=(const SLList& lst); //- Assignment to UIndirectList operator. Takes linear time - void operator=(const UIndirectList&); + void operator=(const UIndirectList& lst); //- Assignment to BiIndirectList operator. Takes linear time - void operator=(const BiIndirectList&); + void operator=(const BiIndirectList& lst); //- Assignment to an initializer list - void operator=(std::initializer_list); + void operator=(std::initializer_list lst); //- Assignment of all entries to the given value - inline void operator=(const T&); + inline void operator=(const T& t); //- Assignment of all entries to zero inline void operator=(const zero); @@ -278,7 +286,7 @@ public: //- Read List from Istream, discarding contents of existing List friend Istream& operator>> - (Istream&, List&); + (Istream& is, List& L); }; @@ -290,7 +298,7 @@ public: // \endcode // Mostly useful for handling command-line arguments template -List readList(Istream&); +List readList(Istream& is); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index 5709c258ec..8aa5bc016a 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,8 +77,8 @@ template template inline Foam::List::List ( - InputIterator first, - InputIterator last, + InputIterator begIter, + InputIterator endIter, const label s ) : @@ -88,10 +88,11 @@ inline Foam::List::List { alloc(); - InputIterator iter = first; + InputIterator iter = begIter; forAll(*this, i) { - this->operator[](i) = *iter++; + this->operator[](i) = *iter; + ++iter; } } } @@ -126,7 +127,7 @@ inline void Foam::List::clear() if (this->v_) { delete[] this->v_; - this->v_ = 0; + this->v_ = nullptr; } this->size_ = 0; diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index fbafc9cf0f..a35334507a 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -28,7 +28,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::SortableList::SortableList() +inline Foam::SortableList::SortableList() {} @@ -51,14 +51,14 @@ Foam::SortableList::SortableList(const Xfer>& values) template -Foam::SortableList::SortableList(const label size) +inline Foam::SortableList::SortableList(const label size) : List(size) {} template -Foam::SortableList::SortableList(const label size, const T& val) +inline Foam::SortableList::SortableList(const label size, const T& val) : List(size, val) {} @@ -72,6 +72,20 @@ Foam::SortableList::SortableList(const SortableList& lst) {} +template +template +inline Foam::SortableList::SortableList +( + InputIterator begIter, + InputIterator endIter +) +: + List(begIter, endIter) +{ + sort(); +} + + template Foam::SortableList::SortableList(std::initializer_list values) : @@ -140,9 +154,9 @@ Foam::Xfer> Foam::SortableList::xfer() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template -inline void Foam::SortableList::operator=(const T& t) +inline void Foam::SortableList::operator=(const T& val) { - UList::operator=(t); + UList::operator=(val); } diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index 65fb6dc7f4..cd005a09c2 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -65,27 +65,32 @@ public: // Constructors //- Null constructor, sort later (eg, after assignment or transfer) - SortableList(); + inline SortableList(); //- Construct from UList, sorting immediately - explicit SortableList(const UList&); + explicit SortableList(const UList& values); //- Construct from transferred List, sorting immediately - explicit SortableList(const Xfer>&); + explicit SortableList(const Xfer>& values); //- Construct given size. Sort later on // The indices remain empty until the list is sorted - explicit SortableList(const label size); + explicit inline SortableList(const label size); //- Construct given size and initial value. Sort later on // The indices remain empty until the list is sorted - SortableList(const label size, const T&); + inline SortableList(const label size, const T& val); + + //- Construct given begin/end iterators. + // Uses std::distance to determine the size. + template + inline SortableList(InputIterator begIter, InputIterator endIter); //- Construct as copy - SortableList(const SortableList&); + inline SortableList(const SortableList& lst); //- Construct from an initializer list, sorting immediately - SortableList(std::initializer_list); + SortableList(std::initializer_list values); // Member Functions @@ -122,16 +127,16 @@ public: // Member Operators //- Assignment of all entries to the given value - inline void operator=(const T&); + inline void operator=(const T& val); //- Assignment to UList operator. Takes linear time - inline void operator=(const UList&); + inline void operator=(const UList& lst); //- Assignment operator. Takes linear time - inline void operator=(const SortableList&); + inline void operator=(const SortableList& lst); //- Assignment to an initializer list - void operator=(std::initializer_list); + void operator=(std::initializer_list lst); };