ENH: avoid std::distance for std::initializer_list
- std::initializer_list has its own size() method, so no need to use std::distance. STYLE/BUG: use separate iterator de-reference and increment in List - avoids unnecessary copying of iterators, and avoids any potentially odd behaviour with the combination with incrementing. ENH: support construct from iterator pair for DynamicList, SortableList
This commit is contained in:
parent
83669e284f
commit
0c53a815ed
@ -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<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream&,
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>&
|
||||
Ostream& os,
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
Istream& operator>>
|
||||
(
|
||||
Istream&,
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>&
|
||||
Istream& is,
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>& 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<T, SizeInc, SizeMult, SizeDiv>&);
|
||||
inline DynamicList
|
||||
(
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
|
||||
//- Construct from UList. Size set to UList size.
|
||||
// Also constructs from DynamicList with different sizing parameters.
|
||||
explicit inline DynamicList(const UList<T>&);
|
||||
explicit inline DynamicList(const UList<T>& lst);
|
||||
|
||||
//- Construct given begin/end iterators.
|
||||
// Uses std::distance to determine the size.
|
||||
template<class InputIterator>
|
||||
inline DynamicList(InputIterator begIter, InputIterator endIter);
|
||||
|
||||
//- Construct from an initializer list. Size set to list size.
|
||||
explicit inline DynamicList(std::initializer_list<T>);
|
||||
explicit inline DynamicList(std::initializer_list<T> lst);
|
||||
|
||||
//- Construct from UIndirectList. Size set to UIndirectList size.
|
||||
explicit inline DynamicList(const UIndirectList<T>&);
|
||||
explicit inline DynamicList(const UIndirectList<T>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
explicit inline DynamicList(const Xfer<List<T>>&);
|
||||
explicit inline DynamicList(const Xfer<List<T>>& 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<T, SizeInc, SizeMult, SizeDiv>& shrink();
|
||||
|
||||
//- Transfer contents of the argument List into this.
|
||||
inline void transfer(List<T>&);
|
||||
inline void transfer(List<T>& lst);
|
||||
|
||||
//- Transfer contents of the argument DynamicList into this.
|
||||
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
|
||||
inline void transfer
|
||||
(
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
|
||||
//- Transfer contents to the Xfer container as a plain List
|
||||
inline Xfer<List<T>> xfer();
|
||||
@ -195,25 +206,25 @@ public:
|
||||
//- Append an element at the end of the list
|
||||
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
|
||||
(
|
||||
const T&
|
||||
const T& t
|
||||
);
|
||||
|
||||
//- Append a List at the end of this list
|
||||
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
|
||||
(
|
||||
const UList<T>&
|
||||
const UList<T>& lst
|
||||
);
|
||||
|
||||
//- Append an initializer list at the end of this list.
|
||||
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
|
||||
(
|
||||
std::initializer_list<T>
|
||||
std::initializer_list<T> lst
|
||||
);
|
||||
|
||||
//- Append a UIndirectList at the end of this list
|
||||
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
|
||||
(
|
||||
const UIndirectList<T>&
|
||||
const UIndirectList<T>& 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<T, SizeInc, SizeMult, SizeDiv>&
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
|
||||
//- Assignment to UList
|
||||
inline void operator=(const UList<T>&);
|
||||
inline void operator=(const UList<T>& lst);
|
||||
|
||||
//- Assignment from initializer list
|
||||
inline void operator=(std::initializer_list<T>);
|
||||
inline void operator=(std::initializer_list<T> lst);
|
||||
|
||||
//- Assignment to UIndirectList
|
||||
inline void operator=(const UIndirectList<T>&);
|
||||
inline void operator=(const UIndirectList<T>& lst);
|
||||
|
||||
|
||||
// STL member functions
|
||||
|
||||
//- Erase an element, move the remaining elements to fill the gap
|
||||
// and resize the List
|
||||
typename UList<T>::iterator erase(typename UList<T>::iterator);
|
||||
typename UList<T>::iterator erase
|
||||
(
|
||||
typename UList<T>::iterator curIter
|
||||
);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
@ -254,15 +268,15 @@ public:
|
||||
// Write DynamicList to Ostream.
|
||||
friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv>
|
||||
(
|
||||
Ostream&,
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>&
|
||||
Ostream& os,
|
||||
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
|
||||
//- Read from Istream, discarding contents of existing DynamicList.
|
||||
friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv>
|
||||
(
|
||||
Istream&,
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>&
|
||||
Istream& is,
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -80,6 +80,19 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
|
||||
{}
|
||||
|
||||
|
||||
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
template<class InputIterator>
|
||||
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
|
||||
(
|
||||
InputIterator begIter,
|
||||
InputIterator endIter
|
||||
)
|
||||
:
|
||||
List<T>(begIter, endIter),
|
||||
capacity_(this->size())
|
||||
{}
|
||||
|
||||
|
||||
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
|
||||
(
|
||||
|
@ -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<class InputIterator>
|
||||
inline FixedList(InputIterator first, InputIterator last);
|
||||
inline FixedList(InputIterator begIter, InputIterator endIter);
|
||||
|
||||
//- Construct from an initializer list
|
||||
inline FixedList(std::initializer_list<T> lst);
|
||||
|
@ -37,7 +37,7 @@ inline Foam::FixedList<T, Size>::FixedList()
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(const T& t)
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = t;
|
||||
}
|
||||
@ -45,11 +45,11 @@ inline Foam::FixedList<T, Size>::FixedList(const T& t)
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
|
||||
inline Foam::FixedList<T, Size>::FixedList(const T lst[Size])
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = v[i];
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,25 +58,33 @@ template<class T, unsigned Size>
|
||||
template<class InputIterator>
|
||||
Foam::FixedList<T, Size>::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<Size; i++)
|
||||
InputIterator iter = begIter;
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter++;
|
||||
v_[i] = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
|
||||
:
|
||||
FixedList<T, Size>(lst.begin(), lst.end())
|
||||
{}
|
||||
{
|
||||
checkSize(lst.size());
|
||||
|
||||
auto iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
@ -84,7 +92,7 @@ inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
|
||||
{
|
||||
checkSize(lst.size());
|
||||
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
@ -97,9 +105,10 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
|
||||
checkSize(lst.size());
|
||||
|
||||
typename SLList<T>::const_iterator iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter++;
|
||||
v_[i] = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +116,7 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
@ -200,7 +209,7 @@ inline void Foam::FixedList<T, Size>::setSize(const label s)
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
@ -276,7 +285,7 @@ inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
@ -287,7 +296,7 @@ inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
|
||||
{
|
||||
checkSize(lst.size());
|
||||
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
}
|
||||
@ -299,9 +308,10 @@ inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
|
||||
checkSize(lst.size());
|
||||
|
||||
typename SLList<T>::const_iterator iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter++;
|
||||
v_[i] = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,17 +320,18 @@ inline void Foam::FixedList<T, Size>::operator=(std::initializer_list<T> lst)
|
||||
{
|
||||
checkSize(lst.size());
|
||||
|
||||
typename std::initializer_list<T>::iterator iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
auto iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter++;
|
||||
v_[i] = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::operator=(const T& t)
|
||||
{
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = t;
|
||||
}
|
||||
@ -464,7 +475,7 @@ inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
|
||||
// Hash incrementally
|
||||
unsigned val = seed;
|
||||
|
||||
for (unsigned i=0; i<Size; i++)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
val = HashT()(lst[i], val);
|
||||
}
|
||||
|
@ -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.
|
||||
@ -160,7 +160,7 @@ Foam::List<T>::List(List<T>& 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<T>::List(List<T>& a, bool reuse)
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::List<T>::List(const UList<T>& a, const labelUList& map)
|
||||
Foam::List<T>::List(const UList<T>& a, const labelUList& mapAddressing)
|
||||
:
|
||||
UList<T>(nullptr, map.size())
|
||||
UList<T>(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<T>::List(const UList<T>& a, const labelUList& map)
|
||||
|
||||
template<class T>
|
||||
template<class InputIterator>
|
||||
Foam::List<T>::List(InputIterator first, InputIterator last)
|
||||
Foam::List<T>::List(InputIterator begIter, InputIterator endIter)
|
||||
:
|
||||
List<T>(first, last, std::distance(first, last))
|
||||
List<T>(begIter, endIter, std::distance(begIter, endIter))
|
||||
{}
|
||||
|
||||
|
||||
@ -231,6 +231,8 @@ Foam::List<T>::List(const PtrList<T>& lst)
|
||||
}
|
||||
|
||||
|
||||
// Note: using first/last is not entirely accurate.
|
||||
// But since the list size is correct, last() is actually ignored.
|
||||
template<class T>
|
||||
Foam::List<T>::List(const SLList<T>& lst)
|
||||
:
|
||||
@ -259,7 +261,7 @@ Foam::List<T>::List(const BiIndirectList<T>& lst)
|
||||
template<class T>
|
||||
Foam::List<T>::List(std::initializer_list<T> lst)
|
||||
:
|
||||
List<T>(lst.begin(), lst.end())
|
||||
List<T>(lst.begin(), lst.end(), lst.size())
|
||||
{}
|
||||
|
||||
|
||||
@ -326,7 +328,7 @@ void Foam::List<T>::setSize(const label newSize)
|
||||
template<class T>
|
||||
void Foam::List<T>::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<T>::transfer(List<T>& a)
|
||||
this->v_ = a.v_;
|
||||
|
||||
a.size_ = 0;
|
||||
a.v_ = 0;
|
||||
a.v_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -419,14 +421,9 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
|
||||
if (this->size_)
|
||||
{
|
||||
label i = 0;
|
||||
for
|
||||
(
|
||||
typename SLList<T>::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<T>::operator=(std::initializer_list<T> lst)
|
||||
{
|
||||
reAlloc(lst.size());
|
||||
|
||||
typename std::initializer_list<T>::iterator iter = lst.begin();
|
||||
auto iter = lst.begin();
|
||||
forAll(*this, i)
|
||||
{
|
||||
this->operator[](i) = *iter++;
|
||||
this->operator[](i) = *iter;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class Ostream;
|
||||
// Forward declaration of friend functions and operators
|
||||
template<class T> class List;
|
||||
|
||||
template<class T> Istream& operator>>(Istream&, List<T>&);
|
||||
template<class T> Istream& operator>>(Istream& is, List<T>& L);
|
||||
|
||||
template<class T, unsigned Size> class FixedList;
|
||||
template<class T> class PtrList;
|
||||
@ -95,22 +95,28 @@ class List
|
||||
|
||||
//- Copy list of given type
|
||||
template<class List2>
|
||||
inline void copyList(const List2&);
|
||||
inline void copyList(const List2& lst);
|
||||
|
||||
//- Allocate storage and copy list of given type
|
||||
template<class List2>
|
||||
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<class InputIterator>
|
||||
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<T>&);
|
||||
List(const List<T>& a);
|
||||
|
||||
//- Copy constructor from list containing another type
|
||||
template<class T2>
|
||||
explicit List(const List<T2>&);
|
||||
explicit List(const List<T2>& a);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
List(const Xfer<List<T>>&);
|
||||
List(const Xfer<List<T>>& lst);
|
||||
|
||||
//- Construct as copy or re-use as specified
|
||||
List(List<T>&, bool reuse);
|
||||
List(List<T>& a, bool reuse);
|
||||
|
||||
//- Construct as subset
|
||||
List(const UList<T>&, const labelUList& mapAddressing);
|
||||
List(const UList<T>& a, const labelUList& mapAddressing);
|
||||
|
||||
//- Construct given start and end iterators
|
||||
//- Construct given begin/end iterators.
|
||||
// Uses std::distance to determine the size.
|
||||
template<class InputIterator>
|
||||
List(InputIterator first, InputIterator last);
|
||||
List(InputIterator begIter, InputIterator endIter);
|
||||
|
||||
//- Construct as copy of FixedList<T, Size>
|
||||
template<unsigned Size>
|
||||
explicit List(const FixedList<T, Size>&);
|
||||
explicit List(const FixedList<T, Size>& lst);
|
||||
|
||||
//- Construct as copy of PtrList<T>
|
||||
explicit List(const PtrList<T>&);
|
||||
explicit List(const PtrList<T>& lst);
|
||||
|
||||
//- Construct as copy of SLList<T>
|
||||
explicit List(const SLList<T>&);
|
||||
explicit List(const SLList<T>& lst);
|
||||
|
||||
//- Construct as copy of UIndirectList<T>
|
||||
explicit List(const UIndirectList<T>&);
|
||||
explicit List(const UIndirectList<T>& lst);
|
||||
|
||||
//- Construct as copy of BiIndirectList<T>
|
||||
explicit List(const BiIndirectList<T>&);
|
||||
explicit List(const BiIndirectList<T>& lst);
|
||||
|
||||
//- Construct from an initializer list
|
||||
List(std::initializer_list<T>);
|
||||
List(std::initializer_list<T> lst);
|
||||
|
||||
//- Construct from Istream
|
||||
List(Istream&);
|
||||
List(Istream& is);
|
||||
|
||||
//- Clone
|
||||
inline autoPtr<List<T>> 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<T>&);
|
||||
inline void append(const UList<T>& lst);
|
||||
|
||||
//- Append a UIndirectList at the end of this list
|
||||
inline void append(const UIndirectList<T>&);
|
||||
inline void append(const UIndirectList<T>& lst);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
void transfer(List<T>&);
|
||||
void transfer(List<T>& a);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
|
||||
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a);
|
||||
|
||||
//- Transfer the contents of the argument List into this list
|
||||
// and annul the argument list
|
||||
void transfer(SortableList<T>&);
|
||||
void transfer(SortableList<T>& a);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<List<T>> 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<T>&);
|
||||
void operator=(const UList<T>& a);
|
||||
|
||||
//- Assignment operator. Takes linear time
|
||||
void operator=(const List<T>&);
|
||||
void operator=(const List<T>& a);
|
||||
|
||||
//- Assignment to SLList operator. Takes linear time
|
||||
void operator=(const SLList<T>&);
|
||||
void operator=(const SLList<T>& lst);
|
||||
|
||||
//- Assignment to UIndirectList operator. Takes linear time
|
||||
void operator=(const UIndirectList<T>&);
|
||||
void operator=(const UIndirectList<T>& lst);
|
||||
|
||||
//- Assignment to BiIndirectList operator. Takes linear time
|
||||
void operator=(const BiIndirectList<T>&);
|
||||
void operator=(const BiIndirectList<T>& lst);
|
||||
|
||||
//- Assignment to an initializer list
|
||||
void operator=(std::initializer_list<T>);
|
||||
void operator=(std::initializer_list<T> 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>> <T>
|
||||
(Istream&, List<T>&);
|
||||
(Istream& is, List<T>& L);
|
||||
};
|
||||
|
||||
|
||||
@ -290,7 +298,7 @@ public:
|
||||
// \endcode
|
||||
// Mostly useful for handling command-line arguments
|
||||
template<class T>
|
||||
List<T> readList(Istream&);
|
||||
List<T> readList(Istream& is);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
@ -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<class T>
|
||||
template<class InputIterator>
|
||||
inline Foam::List<T>::List
|
||||
(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
InputIterator begIter,
|
||||
InputIterator endIter,
|
||||
const label s
|
||||
)
|
||||
:
|
||||
@ -88,10 +88,11 @@ inline Foam::List<T>::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<T>::clear()
|
||||
if (this->v_)
|
||||
{
|
||||
delete[] this->v_;
|
||||
this->v_ = 0;
|
||||
this->v_ = nullptr;
|
||||
}
|
||||
|
||||
this->size_ = 0;
|
||||
|
@ -28,7 +28,7 @@ License
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::SortableList<T>::SortableList()
|
||||
inline Foam::SortableList<T>::SortableList()
|
||||
{}
|
||||
|
||||
|
||||
@ -51,14 +51,14 @@ Foam::SortableList<T>::SortableList(const Xfer<List<T>>& values)
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::SortableList<T>::SortableList(const label size)
|
||||
inline Foam::SortableList<T>::SortableList(const label size)
|
||||
:
|
||||
List<T>(size)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::SortableList<T>::SortableList(const label size, const T& val)
|
||||
inline Foam::SortableList<T>::SortableList(const label size, const T& val)
|
||||
:
|
||||
List<T>(size, val)
|
||||
{}
|
||||
@ -72,6 +72,20 @@ Foam::SortableList<T>::SortableList(const SortableList<T>& lst)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class InputIterator>
|
||||
inline Foam::SortableList<T>::SortableList
|
||||
(
|
||||
InputIterator begIter,
|
||||
InputIterator endIter
|
||||
)
|
||||
:
|
||||
List<T>(begIter, endIter)
|
||||
{
|
||||
sort();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::SortableList<T>::SortableList(std::initializer_list<T> values)
|
||||
:
|
||||
@ -140,9 +154,9 @@ Foam::Xfer<Foam::List<T>> Foam::SortableList<T>::xfer()
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::SortableList<T>::operator=(const T& t)
|
||||
inline void Foam::SortableList<T>::operator=(const T& val)
|
||||
{
|
||||
UList<T>::operator=(t);
|
||||
UList<T>::operator=(val);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<T>&);
|
||||
explicit SortableList(const UList<T>& values);
|
||||
|
||||
//- Construct from transferred List, sorting immediately
|
||||
explicit SortableList(const Xfer<List<T>>&);
|
||||
explicit SortableList(const Xfer<List<T>>& 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<class InputIterator>
|
||||
inline SortableList(InputIterator begIter, InputIterator endIter);
|
||||
|
||||
//- Construct as copy
|
||||
SortableList(const SortableList<T>&);
|
||||
inline SortableList(const SortableList<T>& lst);
|
||||
|
||||
//- Construct from an initializer list, sorting immediately
|
||||
SortableList(std::initializer_list<T>);
|
||||
SortableList(std::initializer_list<T> 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<T>&);
|
||||
inline void operator=(const UList<T>& lst);
|
||||
|
||||
//- Assignment operator. Takes linear time
|
||||
inline void operator=(const SortableList<T>&);
|
||||
inline void operator=(const SortableList<T>& lst);
|
||||
|
||||
//- Assignment to an initializer list
|
||||
void operator=(std::initializer_list<T>);
|
||||
void operator=(std::initializer_list<T> lst);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user