13#include <initializer_list>
40 List(
const std::initializer_list<T>& vCollection) {
42 for (
const auto& item : vCollection) {
51 for (
int i = 0; i < lstOther.m_iCount; ++i) {
52 Add(lstOther.m_pData[i]);
59 if (
this != &lstOther) {
62 for (
int i = 0; i < lstOther.m_iCount; ++i) {
63 Add(lstOther.m_pData[i]);
71 List(
List&& lstOther) noexcept : m_pData(lstOther.m_pData), m_iCount(lstOther.m_iCount), m_iCapacity(lstOther.m_iCapacity) {
72 lstOther.m_pData =
nullptr;
73 lstOther.m_iCount = 0;
74 lstOther.m_iCapacity = 0;
81 if (
this != &lstOther) {
83 m_pData = lstOther.m_pData;
84 m_iCount = lstOther.m_iCount;
85 m_iCapacity = lstOther.m_iCapacity;
86 lstOther.m_pData =
nullptr;
87 lstOther.m_iCount = 0;
88 lstOther.m_iCapacity = 0;
110 if (iValue > m_iCapacity) {
112 for (
int i = 0; i < m_iCount; ++i) {
113 ::new ((
void*)&pNewData[i]) T(std::move(m_pData[i]));
117 m_iCapacity = iValue;
125 return m_pData[iIndex];
132 return m_pData[iIndex];
139 if (m_iCount == m_iCapacity) {
140 SetCapacity(m_iCapacity == 0 ? 4 : m_iCapacity * 2);
142 ::new ((
void*)&m_pData[m_iCount]) T(item);
149 int iNewCount = m_iCount + arrCollection.
GetLength();
150 if (iNewCount > m_iCapacity) {
153 for (
int iIdx = 0; iIdx < arrCollection.
GetLength(); iIdx++) {
154 ::new ((
void*)&m_pData[m_iCount]) T(arrCollection[iIdx]);
161 for (
int i = 0; i < m_iCount; ++i) {
178 for (
int i = 0; i < m_iCount; ++i) {
179 if (m_pData[i] == item)
return i;
190 int high = m_iCount - 1;
191 while (low <= high) {
192 int mid = low + (high - low) / 2;
193 if (m_pData[mid] == item)
return mid;
194 if (m_pData[mid] < item) {
207 if (m_iCount == m_iCapacity) {
208 SetCapacity(m_iCapacity == 0 ? 4 : m_iCapacity * 2);
210 if (iIndex < m_iCount) {
211 ::new ((
void*)&m_pData[m_iCount]) T(std::move(m_pData[m_iCount - 1]));
212 for (
int i = m_iCount - 1; i > iIndex; --i) {
213 m_pData[i] = std::move(m_pData[i - 1]);
215 m_pData[iIndex] = item;
217 ::new ((
void*)&m_pData[m_iCount]) T(item);
237 if (iIndex >= 0 && iIndex < m_iCount) {
238 for (
int i = iIndex; i < m_iCount - 1; ++i) {
239 m_pData[i] = std::move(m_pData[i + 1]);
241 m_pData[m_iCount - 1].~T();
247 T temp = std::move(a);
254 for (
int i = 0; i < m_iCount - 1; ++i) {
255 for (
int j = 0; j < m_iCount - i - 1; ++j) {
256 if (m_pData[j] > m_pData[j + 1]) {
267 template <
typename Predicate>
269 for (
int i = 0; i < m_iCount; ++i) {
270 if (fnMatch(m_pData[i]))
return true;
279 template <
typename Predicate>
281 for (
int i = 0; i < m_iCount; ++i) {
282 if (fnMatch(m_pData[i]))
return m_pData[i];
291 template <
typename Predicate>
294 for (
int i = 0; i < m_iCount; ++i) {
295 if (fnMatch(m_pData[i])) lstResult.
Add(m_pData[i]);
304 template <
typename Predicate>
306 for (
int i = 0; i < m_iCount; ++i) {
307 if (!fnMatch(m_pData[i]))
return false;
316 for (
int iIdx = 0; iIdx < m_iCount; iIdx++) {
317 arrResult[iIdx] = m_pData[iIdx];
326 T*
end() {
return m_pData + m_iCount; }
329 const T*
begin()
const {
return m_pData; }
332 const T*
end()
const {
return m_pData + m_iCount; }
335 T* m_pData =
nullptr;
341 for (
int i = 0; i < m_iCount; ++i) {
Provides methods for creating, manipulating, searching, and sorting arrays.
Defines common cross-platform macros, export decorators, and fundamental types.
Base object class for DotNetDupe mirroring .NET System.Object.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
bool Remove(const T &item)
Removes the first occurrence of a specific object from the List.
List & operator=(List &&lstOther) noexcept
Move assignment operator.
const T & operator[](int iIndex) const
Gets a const reference to the element at the specified index.
List(const List &lstOther)
Copy constructor.
void Sort()
Sorts the elements in the entire List using the default comparer.
T & operator[](int iIndex)
Gets a reference to the element at the specified index.
List(int iCapacity)
Initializes a new instance of the List class with specified initial capacity.
bool TrueForAll(Predicate fnMatch) const
Determines whether every element in the List matches the conditions defined by the specified predicat...
T * end()
Returns a pointer to one past the last element for range-based for loops.
void RemoveAt(int iIndex)
Removes the element at the specified index of the List.
void Insert(int iIndex, const T &item)
Inserts an element into the List at the specified index.
int BinarySearch(const T &item) const
Searches the entire sorted List for an element using the default comparer.
bool Contains(const T &item) const
Determines whether an element is in the List.
List(const std::initializer_list< T > &vCollection)
Initializes a new instance of the List class containing elements from an initializer list.
List & operator=(const List &lstOther)
Copy assignment operator.
int IndexOf(const T &item) const
Searches for the specified object and returns the zero-based index of the first occurrence within the...
bool Exists(Predicate fnMatch) const
Determines whether the List contains elements that match the conditions defined by the specified pred...
void SwapElements(T &a, T &b)
List()
Initializes a new instance of the List class that is empty.
int GetCount() const
Gets the number of elements contained in the List.
const T * begin() const
Returns a const pointer to the first element for range-based for loops.
T Find(Predicate fnMatch) const
Searches for an element that matches the conditions defined by the specified predicate,...
~List() override
Destructor releasing internal buffer resources.
void Add(const T &item)
Adds an object to the end of the List.
int GetCapacity() const
Gets the total number of elements the internal data structure can hold without resizing.
void AddRange(const Array< T > &arrCollection)
Adds the elements of the specified array to the end of the List.
T * begin()
Returns a pointer to the first element for range-based for loops.
List(List &&lstOther) noexcept
Move constructor.
void SetCapacity(int iValue)
Sets the capacity of the internal buffer to a specified value.
Array< T > ToArray() const
Copies the elements of the List to a new Array.
void Clear()
Removes all elements from the List.
List< T > FindAll(Predicate fnMatch) const
Retrieves all the elements that match the conditions defined by the specified predicate.
const T * end() const
Returns a const pointer to one past the last element for range-based for loops.
Supports all classes in the DotNetDupe class hierarchy.
Represents the method that defines a set of criteria and determines whether the specified object meet...
void * AllocateCollectionBuffer(size_t size)
Internal memory allocator for generic collections.
void FreeCollectionBuffer(void *p)
Frees collection buffer allocated with AllocateCollectionBuffer.