56 for (label lower = 0; lower < i; ++lower)
58 Foam::Swap(this->
operator[](lower), this->
operator[](i));
68 for (label upper = size()-1; upper > i; --upper)
70 Foam::Swap(this->
operator[](i), this->
operator[](upper));
82 Foam::Swap(this->
operator[](0), this->
operator[](i));
92 const label upper = size()-1;
96 Foam::Swap(this->
operator[](i), this->
operator[](upper));
104 if (this->size_ != list.size_)
107 <<
"Lists have different sizes: "
108 << this->size_ <<
" != " << list.size() << nl
109 << abort(FatalError);
111 else if (this->size_ > 0)
116 std::copy(list.cbegin(), list.cend(), this->v_);
125 if (this->size_ != list.size())
128 <<
"Lists have different sizes: "
129 << this->size_ <<
" != " << list.size() <<
nl
132 else if (this->size_)
139 const label len = this->size_;
141 auto iter = this->v_;
143 for (label i = 0; i < len; (void)++i, (void)++iter)
156 if constexpr (!is_contiguous_v<T>)
159 <<
"Invalid for non-contiguous data types"
162 return this->size_bytes();
169 const auto iter = std::find(this->
cbegin(), this->
cend(), val);
170 return (iter != this->
cend() ? label(iter - this->
cbegin()) : label(-1));
177 if (
pos >= 0 && pos < this->size())
182 if (len > 0) len +=
pos;
183 if (len < 0 || len > this->size())
188 const auto iter = std::find
190 (this->cbegin() + pos),
191 (this->cbegin() + len),
195 if (iter != (this->cbegin() + len))
197 return label(iter - this->cbegin());
210 if (pos < 0 || pos >= this->size())
212 pos = this->size()-1;
217 if (this->v_[pos] == val)
239 (this->size_ == list.size_)
240 && std::equal(this->cbegin(), this->cend(), list.
cbegin())
258 return std::lexicographical_compare
269 return list.operator<(*this);
276 return !list.operator<(*this);
293 std::sort(list.begin(), list.end());
297template<
class T,
class Compare>
298void Foam::sort(UList<T>& list,
const Compare& comp)
301 std::sort(list.begin(), list.end(), comp);
309 std::stable_sort(list.begin(), list.end());
313template<
class T,
class Compare>
317 std::stable_sort(list.begin(), list.end(), comp);
324 std::shuffle(list.begin(), list.end(), std::default_random_engine());
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.
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.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
bool operator<(const UList< T > &list) const
Compare two ULists lexicographically. Takes linear time.
void checkIndex(const label i) const
Check index is within valid range [0,size).
void swapFirst(const label i)
Swap element with the first element. Fatal on an empty list.
void deepCopy(const UList< T > &list)
Copy elements of the given UList. Sizes must match!
UList(const UList< T > &) noexcept=default
Copy construct, shallow copy.
iterator end() noexcept
Return an iterator to end traversing the UList.
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
bool operator>=(const UList< T > &list) const
Return true if !(a < b). Takes linear time.
bool operator!=(const UList< T > &list) const
The opposite of the equality operation. Takes linear time.
std::streamsize byteSize() const
Number of contiguous bytes for the List data, runtime FatalError if type is not contiguous.
void checkSize(const label size) const
Check size is within valid range [0,size].
bool operator>(const UList< T > &list) const
Compare two ULists lexicographically. Takes linear time.
void moveFirst(const label i)
Move element to the first position.
void size(const label n)
Older name for setAddressableSize.
bool operator==(const UList< T > &list) const
Equality operation on ULists of the same type.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
labelRange validateRange(const labelRange &requestedRange) const
Return a validated (start,size) subset range, which means that it always addresses a valid section of...
bool operator<=(const UList< T > &list) const
Return true if !(a > b). Takes linear time.
label find(const T &val) const
Find index of the first occurrence of the value.
void checkStart(const label start) const
Check start is within valid range [0,size).
A range or interval of labels defined by a start and a size.
labelRange subset0(label len) const
Calculate the intersection with the given 0/size range.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
dimensionedScalar pos(const dimensionedScalar &ds)
void shuffle(UList< T > &list)
Randomise the list order.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
void sort(UList< T > &list)
Sort the list.
errorManip< error > abort(error &err)
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr bool is_contiguous_v
The is_contiguous value of Type (after stripping of qualifiers).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void stableSort(UList< T > &list)
Stable sort the list.
constexpr char nl
The newline '\n' character (0x0a).