33template<
class T,
int SizeMin>
34template<
class ListType>
35inline void Foam::DynamicList<T, SizeMin>::doAssignDynList
40 const label len = list.size();
45 List<T>::setAddressableSize(capacity_);
46 List<T>::resize_nocopy(len);
47 capacity_ = List<T>::size();
51 List<T>::setAddressableSize(len);
52 List<T>::operator=(list);
56template<
class T,
int SizeMin>
57inline void Foam::DynamicList<T, SizeMin>::doCapacity_copy
60 const label newCapacity
63 if (newCapacity == capacity_)
69 const label currLen = std::min(List<T>::size(), newCapacity);
72 count = std::min(count, currLen);
75 List<T>::setAddressableSize(capacity_);
79 List<T>::resize_copy(count, newCapacity);
83 List<T>::resize_nocopy(newCapacity);
86 capacity_ = List<T>::size();
87 List<T>::setAddressableSize(currLen);
91template<
class T,
int SizeMin>
92inline void Foam::DynamicList<T, SizeMin>::doReserve_copy
101 const label currLen = List<T>::size();
104 count = std::min(count, currLen);
107 List<T>::setAddressableSize(capacity_);
116 List<T>::resize_copy(count, capacity_);
120 List<T>::resize_nocopy(capacity_);
123 capacity_ = List<T>::size();
124 List<T>::setAddressableSize(currLen);
131template<
class T,
int SizeMin>
139template<
class T,
int SizeMin>
149template<
class T,
int SizeMin>
152 std::pair<label,label> sizing
155 List<
T>(std::
max(sizing.first, sizing.second)),
162template<
class T,
int SizeMin>
170 capacity_(List<
T>::
size())
174template<
class T,
int SizeMin>
182 capacity_(List<
T>::
size())
186template<
class T,
int SizeMin>
193 capacity_(List<
T>::
size())
197template<
class T,
int SizeMin>
198template<
int AnySizeMin>
205 capacity_(List<
T>::
size())
209template<
class T,
int SizeMin>
216 capacity_(List<
T>::
size())
220template<
class T,
int SizeMin>
227 List<
T>(list, indices),
228 capacity_(List<
T>::
size())
232template<
class T,
int SizeMin>
240 capacity_(List<
T>::
size())
244template<
class T,
int SizeMin>
247 std::initializer_list<T> lst
255template<
class T,
int SizeMin>
263 capacity_(List<
T>::
size())
267template<
class T,
int SizeMin>
273 List<T>(std::move(
static_cast<List<T>&
>(list))),
274 capacity_(list.capacity())
276 list.setCapacity_unsafe(0);
280template<
class T,
int SizeMin>
281template<
int AnySizeMin>
287 List<
T>(std::move(static_cast<List<
T>&>(list))),
290 list.setCapacity_unsafe(0);
294template<
class T,
int SizeMin>
300 List<T>(std::move(list)),
307template<
class T,
int SizeMin>
308inline std::streamsize
311 return std::streamsize(capacity_)*
sizeof(
T);
315template<
class T,
int SizeMin>
326template<
class T,
int SizeMin>
333 doCapacity_copy(0, len);
337template<
class T,
int SizeMin>
348template<
class T,
int SizeMin>
355 doReserve_copy(0, len);
359template<
class T,
int SizeMin>
387template<
class T,
int SizeMin>
398template<
class T,
int SizeMin>
406 doReserve_copy(count, len);
411template<
class T,
int SizeMin>
423template<
class T,
int SizeMin>
434template<
class T,
int SizeMin>
457template<
class T,
int SizeMin>
464template<
class T,
int SizeMin>
477template<
class T,
int SizeMin>
481 if (currLen < capacity_)
490template<
class T,
int SizeMin>
498 static_cast<const List<T>*
>(
this)
499 ==
static_cast<const List<T>*
>(&other)
507 this->shrink_to_fit();
510 UList<T>::swap(other);
517template<
class T,
int SizeMin>
518template<
int AnySizeMin>
528 static_cast<const List<T>*
>(
this)
529 ==
static_cast<const List<T>*
>(&other)
537 UList<T>::swap(other);
540 std::swap(capacity_, other.capacity_);
544template<
class T,
int SizeMin>
557template<
class T,
int SizeMin>
558template<
int AnySizeMin>
569 static_cast<const List<T>*
>(
this)
570 ==
static_cast<const List<T>*
>(&other)
578 List<T>::setAddressableSize(capacity_);
579 List<T>::transfer(
static_cast<List<T>&
>(other));
587template<
class T,
int SizeMin>
588template<
class... Args>
604template<
class T,
int SizeMin>
617template<
class T,
int SizeMin>
630template<
class T,
int SizeMin>
640 static_cast<const List<T>*
>(
this)
641 ==
static_cast<const List<T>*
>(&list)
646 <<
"Attempted push_back to self"
650 const label idx = List<T>::size();
653 std::copy(list.
begin(), list.
end(), this->begin(idx));
657template<
class T,
int SizeMin>
667 std::copy(list.
begin(), list.
end(), this->begin(idx));
671template<
class T,
int SizeMin>
674 std::initializer_list<T> list
678 resize(idx + list.size());
680 std::copy(list.begin(), list.end(), this->begin(idx));
684template<
class T,
int SizeMin>
695 const label idx = this->size();
696 const label
n = list.
size();
699 auto iter = this->begin(idx);
701 for (label i = 0; i <
n; (void)++i, (void)++iter)
708template<
class T,
int SizeMin>
718 static_cast<const List<T>*
>(
this)
719 ==
static_cast<const List<T>*
>(&list)
724 <<
"Attempted push_back to self"
725 << abort(FatalError);
728 const label idx = List<T>::size();
732 std::move(list.
begin(), list.
end(), this->begin(idx));
738template<
class T,
int SizeMin>
739template<
int AnySizeMin>
749 static_cast<const List<T>*
>(
this)
750 ==
static_cast<const List<T>*
>(&list)
755 <<
"Attempted push_back to self"
759 const label idx = List<T>::size();
763 std::move(list.
begin(), list.
end(), this->begin(idx));
769template<
class T,
int SizeMin>
772 if (this->contains(val))
784template<
class T,
int SizeMin>
787 if (
n >= this->size())
798template<
class T,
int SizeMin>
802 const label idx = List<T>::size() - 1;
807 <<
"List is empty" << abort(FatalError);
810 const T& val = List<T>::operator[](idx);
818template<
class T,
int SizeMin>
841template<
class T,
int SizeMin>
851template<
class T,
int SizeMin>
854 std::initializer_list<label> start_size
857 return this->removeElements(this->
validateRange(start_size));
861template<
class T,
int SizeMin>
871template<
class T,
int SizeMin>
874 std::initializer_list<label> start_size
883template<
class T,
int SizeMin>
898template<
class T,
int SizeMin>
908template<
class T,
int SizeMin>
918template<
class T,
int SizeMin>
924 doAssignDynList(lst);
928template<
class T,
int SizeMin>
935 doAssignDynList(lst);
939template<
class T,
int SizeMin>
949 static_cast<const List<T>*
>(
this)
950 ==
static_cast<const List<T>*
>(&list)
957 doAssignDynList(list);
961template<
class T,
int SizeMin>
962template<
int AnySizeMin>
972 static_cast<const List<T>*
>(
this)
973 ==
static_cast<const List<T>*
>(&list)
980 doAssignDynList(list);
984template<
class T,
int SizeMin>
987 std::initializer_list<T> lst
990 doAssignDynList(lst);
994template<
class T,
int SizeMin>
1012 doAssignDynList(list);
1016template<
class T,
int SizeMin>
1026template<
class T,
int SizeMin>
1036template<
class T,
int SizeMin>
1037template<
int AnySizeMin>
1043 this->transfer(list);
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
constexpr DynamicList() noexcept
Default construct, an empty list without allocation.
T remove()
Remove and return the last element. Fatal on an empty list.
void transfer(List< T > &list)
Transfer contents of the argument List into this.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
void resize_nocopy(const label len)
Alter addressable list size, allocating new space if required without necessarily recovering old cont...
void setCapacity_nocopy(const label len)
Alter the size of the underlying storage, without retaining old content.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
void setCapacity_unsafe(label len) noexcept
Change the value for the list capacity directly (ADVANCED, UNSAFE) Does not perform any memory manage...
void reserve_nocopy(const label len)
Reserve allocation space for at least this size, allocating new space if required without retaining o...
void reserve_exact(const label len)
Reserve allocation space for at least this size, allocating new space if required and retaining old c...
std::streamsize capacity_bytes() const noexcept
Number of contiguous bytes of the underlying storage.
void resize_copy(label count, const label len)
Alter addressable size, retaining the first count contents.
void shrink_to_fit()
Shrink the allocated space to the number of elements used.
void swap(List< T > &other)
Swap with plain List content. Implies shrink_to_fit().
void clearStorage()
Clear the list and delete storage.
label push_uniq(const T &val)
Append an element if not already in the list.
void push_back(const T &val)
Copy append an element to the end of this list.
label capacity() const noexcept
Size of the underlying storage.
friend Ostream & operator(Ostream &os, const DynamicList< T, SizeMin > &list)
Write to Ostream.
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content.
void reserve(const label len)
Reserve allocation space for at least this size, allocating new space if required and retaining old c...
label subset(const labelRange &range)
Retain a (start,size) subset from the list.
void resize_fill(const label len, const T &val)
Alter addressable size and set val for all addressed entries.
void setCapacity(const label len)
Alter the size of the underlying storage.
A 1D vector of objects of type <T> with a fixed length <N>.
static constexpr label size() noexcept
Return the number of elements in the FixedList.
iterator end() noexcept
Return an iterator to end traversing the FixedList.
iterator begin() noexcept
Return an iterator to begin traversing the FixedList.
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
label size() const noexcept
The number of elements in the list.
iterator end()
Return an iterator at end of list.
iterator begin()
Return an iterator at begin of list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
void resize_copy(label count, const label len)
Change allocated size of list, retaining the first count elements.
void resize(const label len)
Adjust allocated size of list.
void clear()
Clear the list, i.e. set size to zero.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
void moveLast(const label i)
Move element to the last position.
void swapLast(const label i)
Swap element with the last element. Fatal on an empty list.
T & first()
Access first element of the list, position [0].
iterator begin() noexcept
Return an iterator to begin traversing the UList.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
bool contains(const T &val) const
True if the value is contained in the list.
iterator end() noexcept
Return an iterator to end traversing the UList.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
label size() const noexcept
The number of elements in the container.
void size(const label n)
Older name for setAddressableSize.
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
T & operator[](const label i)
Return element of UList.
labelRange validateRange(const labelRange &requestedRange) const
Return a validated (start,size) subset range, which means that it always addresses a valid section of...
UList< T > & operator=(const UList< T > &)=delete
No copy assignment (default: shallow copy).
A range or interval of labels defined by a start and a size.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
patchWriters resize(patchIds.size())
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
IntType reserve_size(IntType requested, IntType capacity) noexcept
Calculate a reserve size (eg, doubling) based on the requested length and the current capacity.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
UList< label > labelUList
A UList of labels.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)
#define FOAM_UNLIKELY(cond)