DynamicList: Added initialized constructor and STL erase function

This commit is contained in:
Henry Weller
2016-03-04 11:28:35 +00:00
parent 898693713c
commit 1df60791d8
2 changed files with 49 additions and 0 deletions

View File

@ -104,6 +104,9 @@ public:
//- Construct given size.
explicit inline DynamicList(const label);
//- Construct with given size and value for all elements.
inline DynamicList(const label, const T&);
//- Construct copy.
inline DynamicList(const DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
@ -224,6 +227,12 @@ public:
inline void operator=(const UIndirectList<T>&);
// 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);
// IOstream operators

View File

@ -49,6 +49,18 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
const label nElem,
const T& a
)
:
List<T>(nElem, a),
capacity_(nElem)
{}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
@ -483,4 +495,32 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
}
// * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
typename Foam::UList<T>::iterator
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::erase
(
typename UList<T>::iterator curIter
)
{
typename Foam::UList<T>::iterator iter = curIter;
typename Foam::UList<T>::iterator nextIter = curIter;
if (iter != this->end())
{
++iter;
while (iter != this->end())
{
*nextIter++ = *iter++;
}
this->setSize(this->size() - 1);
}
return curIter;
}
// ************************************************************************* //