16#include <initializer_list>
34 void Allocate(
int iLength) {
43 for (
int i = 0; i < m_iLength; ++i) {
52 void SwapElements(T& a, T& b) {
53 T temp = std::move(a);
66 for (
int i = 0; i < m_iLength; ++i) {
67 ::new ((
void*)&m_pData[i]) T();
74 Array(
const T* pData,
int iLength) {
77 for (
int i = 0; i < m_iLength; ++i) {
78 ::new ((
void*)&m_pData[i]) T(pData[i]);
81 for (
int i = 0; i < m_iLength; ++i) {
82 ::new ((
void*)&m_pData[i]) T();
89 Array(
const std::initializer_list<T>& vItems) {
90 Allocate(
static_cast<int>(vItems.size()));
92 for (
const auto& item : vItems) {
93 ::new ((
void*)&m_pData[iIdx++]) T(item);
99 Allocate(other.m_iLength);
100 for (
int i = 0; i < m_iLength; ++i) {
101 ::new ((
void*)&m_pData[i]) T(other.m_pData[i]);
107 if (
this != &other) {
109 Allocate(other.m_iLength);
110 for (
int i = 0; i < m_iLength; ++i) {
111 ::new ((
void*)&m_pData[i]) T(other.m_pData[i]);
118 Array(
Array&& other) noexcept : m_pData(other.m_pData), m_iLength(other.m_iLength) {
119 other.m_pData =
nullptr;
125 if (
this != &other) {
127 m_pData = other.m_pData;
128 m_iLength = other.m_iLength;
129 other.m_pData =
nullptr;
156 T*
end() {
return m_pData + m_iLength; }
159 const T*
begin()
const {
return m_pData; }
162 const T*
end()
const {
return m_pData + m_iLength; }
166 bool IsNull()
const {
return m_iLength == 0; }
172 const T&
operator[](
int iIndex)
const {
return m_pData[iIndex]; }
178 for (
int iIdx = 0; iIdx < m_iLength; ++iIdx) {
179 if (m_pData[iIdx] == value)
return iIdx;
188 for (
int iIdx = m_iLength - 1; iIdx >= 0; --iIdx) {
189 if (m_pData[iIdx] == value)
return iIdx;
196 for (
int i = 0; i < m_iLength - 1; ++i) {
197 for (
int j = 0; j < m_iLength - i - 1; ++j) {
198 if (m_pData[j] > m_pData[j + 1]) {
199 SwapElements(m_pData[j], m_pData[j + 1]);
208 int right = m_iLength - 1;
209 while (left < right) {
210 SwapElements(m_pData[left], m_pData[right]);
218 for (
int i = 0; i < m_iLength; ++i) {
231 for (
int i = 0; i < m_iLength; ++i) {
232 if (fnPredicate(m_pData[i]))
return true;
239 for (
int i = 0; i < m_iLength; ++i) {
240 if (fnPredicate(m_pData[i]))
return m_pData[i];
248 for (
int i = 0; i < m_iLength; ++i) {
249 if (fnPredicate(m_pData[i])) count++;
253 for (
int i = 0; i < m_iLength; ++i) {
254 if (fnPredicate(m_pData[i])) {
255 arrNew[idx++] = m_pData[i];
263 for (
int i = 0; i < m_iLength; ++i) {
264 if (fnPredicate(m_pData[i]))
return i;
271 for (
int i = m_iLength - 1; i >= 0; --i) {
272 if (fnPredicate(m_pData[i]))
return m_pData[i];
279 for (
int i = m_iLength - 1; i >= 0; --i) {
280 if (fnPredicate(m_pData[i]))
return i;
287 for (
int i = 0; i < m_iLength; ++i) {
288 fnAction(m_pData[i]);
294 for (
int i = 0; i < m_iLength; ++i) {
295 if (!fnPredicate(m_pData[i]))
return false;
314 for (
int iIdx = 0; iIdx <
GetLength(); ++iIdx) {
315 arrTarget[iIndex + iIdx] = m_pData[iIdx];
327 for (
int iIdx = 0; iIdx < iLength; ++iIdx) {
328 arrDestination[iIdx] = arrSource[iIdx];
Encapsulates a delegate method that has parameters and returns void.
Defines the exception thrown when an invalid argument is provided to a method.
Defines the exception thrown when an argument value is outside the acceptable range of values.
Defines common cross-platform macros, export decorators, and fundamental types.
Base object class for DotNetDupe mirroring .NET System.Object.
Represents the method that defines a set of criteria and determines whether the specified object meet...
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Encapsulates a method that has parameters and does not return a value.
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
ArgumentOutOfRangeException(const String &sMessage)
Initializes a new instance of the ArgumentOutOfRangeException class with a specified error message.
Array(int iLength)
Initializes an Array of the specified length with default-constructed elements.
Array()=default
Initializes an empty Array instance.
Array & operator=(const Array &other)
Copy assignment operator.
const T * end() const
Returns a const iterator to the element following the last element of the array.
bool Exists(const Predicate< T > &fnPredicate) const
Determines whether the specified array contains elements that match the conditions defined by the spe...
int FindIndex(const Predicate< T > &fnPredicate) const
Searches for an element that matches the conditions defined by the specified predicate,...
void Sort()
Sorts the elements in an entire Array using the default comparison.
bool TrueForAll(const Predicate< T > &fnPredicate) const
Determines whether every element in the array matches the conditions defined by the specified predica...
Array< T > FindAll(const Predicate< T > &fnPredicate) const
Retrieves all the elements that match the conditions defined by the specified predicate.
static void Copy(Array< T > &arrSource, Array< T > &arrDestination, int iLength)
Copies a range of elements from an Array starting at the first element and pastes them to another Arr...
int LastIndexOf(const T &value) const
Searches for the specified object and returns the index of the last occurrence.
void Reverse()
Reverses the sequence of the elements in the entire Array.
T Find(const Predicate< T > &fnPredicate) const
Searches for an element that matches the conditions defined by the specified predicate,...
void Clear()
Sets a range of elements in the Array to the default value of each element type.
const T * GetData() const
Gets a const pointer to the contiguous internal element buffer.
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
const T * begin() const
Returns a const iterator to the first element of the array.
Array(const T *pData, int iLength)
Initializes an Array by copying elements from a raw pointer buffer.
~Array() override
Destroys array elements and releases allocated storage.
T & operator[](int iIndex)
Accesses the element at the specified index.
Array & operator=(Array &&other) noexcept
Move assignment operator.
int FindLastIndex(const Predicate< T > &fnPredicate) const
Searches for an element that matches the conditions defined by the specified predicate,...
Array(const std::initializer_list< T > &vItems)
Initializes an Array from an initializer list of elements.
T * end()
Returns an iterator to the element following the last element of the array.
T * GetData()
Gets a pointer to the contiguous internal element buffer.
Array(const Array &other)
Copy constructor. Performs a deep copy of elements.
int IndexOf(const T &value) const
Searches for the specified object and returns the index of its first occurrence.
void CopyTo(Array< T > &arrTarget, int iIndex)
Copies all elements of the current Array to the specified destination Array starting at the specified...
T * begin()
Returns an iterator to the first element of the array.
Array(Array &&other) noexcept
Move constructor.
void ForEach(const Action< T > &fnAction)
Performs the specified action on each element of the specified array.
const T & operator[](int iIndex) const
Accesses the const element at the specified index.
T FindLast(const Predicate< T > &fnPredicate) const
Searches for an element that matches the conditions defined by the specified predicate,...
bool IsNull() const
Checks whether the array has zero length.
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.