System::Array class

Array class

Class that represents an array data structure. Objects of this class should only be allocated using System::MakeArray() and System::MakeObject() functions. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

template<typename T>class Array : public virtual System::Object,
                                  public System::Collections::Generic::IList<T>
ParameterDescription
TType of elements of an array

Nested classes

Methods

MethodDescription
Add(const T&) overrideNot supported because the array represented by the current object is read-only.
Array()Constructs an empty array.
Array(int, const T&)Filling constructor.
Array(typename std::enable_if<std::is_arithmetic<T>::value&&std::is_arithmetic<ValueType>::value&&std::is_convertible<ValueType, T>::value, int>::type, ValueType)Filling constructor.
Array(int, const T)Filling constructor.
Array(vector_t&&)Move constructor.
Array(const vector_t&)Copy constructor.
Array(const std::vector<Q>&)Constructs an Array object and fills it with values copied from an std::vector object whose values’ type is the same as T but different from UnderlyingType.
Array(std::vector<Q>&&)Constructs an Array object and fills it with values moved from an std::vector object whose values’ type is the same as T but different from UnderlyingType.
Array(std::initializer_list<UnderlyingType>)Constructs an Array object and fills it with values from the specified initializer list containing elements of UnderlyingType type.
Array(const std::array<UnderlyingType, InitArraySize>&)Constructs an Array object and fills it with values from the specified array containing elements of UnderlyingType type.
Array(std::initializer_list<bool>, int)Constructs an Array object and fills it with values from the specified initializer list containing elements of bool type.
begin()Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end().
begin() constReturns an iterator to the first element of the const-qualified container. If the container is empty, the returned iterator will be equal to end().
static BinarySearch(System::ArrayPtr<T>, const T&)Performs binary search in the sorted array.
static BinarySearch(System::ArrayPtr<T>, const Y&, const SharedPtr<Collections::Generic::IComparer<Z>>&)NOT IMPLEMENTED.
cbegin() constReturns an iterator to the first const-qualified element of the container. If the container is empty, the returned iterator will be equal to cend().
cend() constReturns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.
Clear() overrideNot supported because the array represented by the current object is read-only.
static Clear(const ArrayPtr<Type>&, int, int)Replaces count values starting at the startIndex index in the specified array with default values.
Clone()Clones the array.
Contains(const T&) const overrideDetermines if the specified item is in the array.
static ConvertAll(ArrayPtr<InputType>, Converter<InputType, OutputType>)Constructs a new Array object and fills it with elements of the specified array converted to OutputType type using the specified converter delegate.
static ConvertAll(ArrayPtr<InputType>, std::function<OutputType(InputType)>)Constructs a new Array object and fills it with elements of the specified array converted to OutputType type using the specified converter function object.
static Copy(const ArrayPtr<SrcType>&, const ArrayPtr<DstType>&, int64_t)Copies the specified number of elements from the source array to the destination array.
static Copy(System::Details::ArrayView<SrcType>, const ArrayPtr<DstType>&, int64_t)Copies the specified number of elements from the source array view to the destination array.
static Copy(const ArrayPtr<SrcType>&, System::Details::ArrayView<DstType>, int64_t)Copies the specified number of elements from the source array to the destination array view.
static Copy(System::Details::ArrayView<SrcType>, System::Details::ArrayView<DstType>, int64_t)Copies the specified number of elements from the source array view to the destination array view.
static Copy(System::Details::StackArray<SrcType, N>&, const ArrayPtr<DstType>&, int64_t)Copies the specified number of elements from the source array on stack to the destination array.
static Copy(const ArrayPtr<SrcType>&, System::Details::StackArray<DstType, N>&, int64_t)Copies the specified number of elements from the source array to the destination array on stack.
static Copy(System::Details::StackArray<SrcType, NS>&, System::Details::StackArray<DstType, ND>&, int64_t)Copies the specified number of elements from the source array on stack to the destination array on stack.
static Copy(const ArrayPtr<SrcType>&, int64_t, const ArrayPtr<DstType>&, int64_t, int64_t)Copies a specified number of elements from the source array starting at the specified index to the specified position in destination array.
static Copy(System::Details::ArrayView<SrcType>, int64_t, const ArrayPtr<DstType>&, int64_t, int64_t)Copies a specified number of elements from the source array view starting at the specified index to the specified position in destination array.
static Copy(const ArrayPtr<SrcType>&, int64_t, System::Details::ArrayView<DstType>, int64_t, int64_t)Copies a specified number of elements from the source array starting at the specified index to the specified position in destination array view.
static Copy(System::Details::ArrayView<SrcType>, int64_t, System::Details::ArrayView<DstType>, int64_t, int64_t)Copies a specified number of elements from the source array view starting at the specified index to the specified position in destination array view.
static Copy(System::Details::StackArray<SrcType, N>&, int64_t, const ArrayPtr<DstType>&, int64_t, int64_t)Copies a specified number of elements from the source array on stack starting at the specified index to the specified position in destination array.
static Copy(const ArrayPtr<SrcType>&, int64_t, System::Details::StackArray<DstType, N>&, int64_t, int64_t)Copies a specified number of elements from the source array starting at the specified index to the specified position in destination array on stack.
static Copy(System::Details::StackArray<SrcType, NS>&, int64_t, System::Details::StackArray<DstType, ND>&, int64_t, int64_t)Copies a specified number of elements from the source array on stack starting at the specified index to the specified position in destination array on stack.
static Copy(System::Details::ArrayView<SrcType>&, int64_t, System::Details::StackArray<DstType, ND>&, int64_t, int64_t)Copies a specified number of elements from the source array view starting at the specified index to the specified position in destination array on stack.
CopyTo(ArrayPtr<T>, int) overrideCopies all elements of the current array to the specified destination array. Elements are inserted into destination array starting at index specified by arrayIndex argument.
CopyTo(const ArrayPtr<DstType>&, int64_t) constCopies all elements of the current array to the specified destination array. Elements are inserted into the destination array starting at index specified by dstIndex argument.
CopyTo(const System::Details::ArrayView<DstType>&, int64_t) constCopies all elements of the current array to the specified destination array view. Elements are inserted into the destination array view starting at index specified by dstIndex argument.
CopyTo(const ArrayPtr<DstType>&, int64_t, int64_t, int64_t) constCopies a specified number of elements from the current array starting at specified position to specified destination array. Elements are inserted into the destination array starting at index specified by dstIndex argument.
CopyTo(const System::Details::ArrayView<DstType>&, int64_t, int64_t, int64_t) constCopies a specified number of elements from the current array starting at specified position to specified destination array view. Elements are inserted into the destination array view starting at index specified by dstIndex argument.
Count() constReturns a number that represents the total number of all elements in all dimensions of the array.
crbegin() constReturns a reverse iterator to the first element of the reversed container. It corresponds to the last element of the non-reversed container. If the container is empty, the returned iterator is equal to crend().
crend() constReturns a reverse iterator to the element following the last element of the reversed container. It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behavior.
data()Returns a reference to the internal data structure used to store the array elements.
data() constReturns a constant reference to the internal data structure used to store the array elements.
data_ptr()Returns a raw pointer to the beginning of the memory buffer where the array elements are stored.
data_ptr() constReturns a constant raw pointer to the beginning of the memory buffer where the array elements are stored.
end()Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.
end() constReturns an iterator to the element following the last element of the const-qualified container. This element acts as a placeholder; attempting to access it results in undefined behavior.
static Exists(ArrayPtr<T>, std::function<bool(T)>)Determines if the specified Array object contains an element that satisfies requirements of the specified predicate.
static Find(System::ArrayPtr<T>, System::Predicate<T>)Searches for the first element in the specified array that satisfies the conditions of the specified predicate.
static FindAll(System::ArrayPtr<T>, System::Predicate<T>)Retrieves all the elements that match the conditions defined by the specified predicate.
static FindIndex(System::ArrayPtr<T>, System::Predicate<T>)Searches for the first element in the specified array that satisfies the conditions of the specified predicate.
static ForEach(const ArrayPtr<T>&, System::Action<T>)Performs specified action on each element of the specified array.
get_Count() const overrideReturns the size of the array.
get_IsReadOnly() const overrideIndicates whether the array is read-only.
get_Length() constReturns 32-bit integer that represents the total number of all elements in all dimensions of the array.
get_LongLength() constReturns 64-bit integer that represents the total number of all elements in all dimensions of the array.
get_Rank() constNOT IMPLEMENTED.
GetEnumerator() overrideReturns a pointer to Enumerator object that provides IEnumerator interface to elements of the array represented by the current object.
GetLength(int)Returns the number of elements in the specified dimension.
GetLongLength(int)Returns the number of elements in the specified dimension as 64-bit integer.
GetLowerBound(int) constReturns the lower bound of the specified dimension.
GetSizeTLength() constReturns an std::size_t variable that represents the total number of all elements in all dimensions of the array.
GetUpperBound(int)Returns the upper bound of the specified dimension.
idx_get(int) const overrideReturns the item at the specified index.
idx_set(int, T) overrideSets the specified value as the item of the array at the specified index.
IndexOf(const T&) const overrideDetermines the index of the first occurrence of the specified item in the array.
static IndexOf(const ArrayPtr<ArrayType>&, const ValueType&)Determines the index of the first occurrence of specified item in the array.
static IndexOf(const ArrayPtr<ArrayType>&, const ValueType&, int)Determines the index of the first occurrence of the specified item in the array starting from the specified index.
static IndexOf(const ArrayPtr<ArrayType>&, const ValueType&, int, int)Determines the index of the first occurrence of the specified item in a range of items of the array specified by the start index and the number of elements in the range.
Init(const T)Fills the array represented by the current object with the values from the specified array.
Initialize()Fills the array with the default constructed objects of type T.
Insert(int, const T&) overrideNot supported because array represented by the current object is read-only.
static LastIndexOf(const ArrayPtr<ArrayType>&, const ValueType&, int, int)Determines the index of the last occurrence of the specified item in a range of items of the array specified by the start index and the number of elements in the range.
static LastIndexOf(const ArrayPtr<ArrayType>&, const ValueType&, int)Determines the index of the last occurrence of the specified item in the array starting from the specified index.
static LastIndexOf(const ArrayPtr<ArrayType>&, const ValueType&)Determines the index of the last occurrence of the specified item in the array.
Max() constFinds the largest element in the array using operator<() to compare elements.
Min() constFinds the smallest element in the array using operator<() to compare elements.
operator[](int)Returns an item at the specified index.
operator[](int) constReturns an item at the specified index.
rbegin()Returns a reverse iterator to the first element of the reversed container. It corresponds to the last element of the non-reversed container. If the container is empty, the returned iterator is equal to rend().
rbegin() constReturns a reverse iterator to the first element of the reversed container. It corresponds to the last element of the non-reversed container. If the container is empty, the returned iterator is equal to rend().
Remove(const T&) overrideNot supported because the array represented by the current object is read-only.
RemoveAt(int) overrideNot supported because array represented by the current object is read-only.
rend()Returns a reverse iterator to the element following the last element of the reversed container. It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behavior.
rend() constReturns a reverse iterator to the element following the last element of the reversed container. It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behavior.
static Resize(ArrayPtr<Type>&, int)Changes the size of the specified array to the specified value or crates new array with specified size.
static Reverse(const ArrayPtr<Type>&)Reverses elements in the specified array.
static Reverse(const ArrayPtr<Type>&, int, int)Reverses a range of elements in the specified array.
SetTemplateWeakPtr(uint32_t) overrideMakes array treat stored pointers as weak (if applicable).
SetValue(const T&, int)Sets value of the element at specified index.
static Sort(const ArrayPtr<Type>&)Sorts elements in the specified array using default comparer.
static Sort(const ArrayPtr<Type>&, int, int)Sorts a range of elements in the specified array using default comparer.
static Sort(const ArrayPtr<Type>&, const SharedPtr<System::Collections::Generic::IComparer<T>>&)Sorts elements in the specified array using specified comparer.
static Sort(const ArrayPtr<Type>&, const SharedPtr<System::Collections::Generic::IComparer<Y>>&)NOT IMPLEMENTED.
static Sort(const ArrayPtr<TKey>&, const ArrayPtr<TValue>&)Sorts two arrays one containing keys and the other - corresponding items, based on the values of array containing keys, elements of which are compared using operator<.
static Sort(const ArrayPtr<TKey>&, const ArrayPtr<TValue>&, int, int)Sorts two arrays one containing keys and the other - corresponding items, based on the values of array containing keys, elements of which are compared using default comparer.
static TrueForAll(System::ArrayPtr<T>, System::Predicate<T>)Determines whether all elements in the specified array satisfy the conditions defined by specified predicate.
virtualizeBeginConstIterator() const overrideGets the implementation of begin const iterator for the current container.
virtualizeBeginIterator() overrideGets the implementation of begin iterator for the current container.
virtualizeEndConstIterator() const overrideGets the implementation of end const iterator for the current container.
virtualizeEndIterator() overrideGets the implementation of end iterator for the current container.

Typedefs

TypedefDescription
const_iteratorConst iterator type.
const_reverse_iteratorConst reverse iterator type.
EnumerablePtrAn alias for shared pointer type pointing to IEnumerable object containing elements of type T.
EnumeratorPtrAn alias for shared pointer type pointing to IEnumerator object containing elements of type T.
iteratorIterator type.
reverse_iteratorReverse iterator type.
UnderlyingTypeAlias for the type used to represent each element of the array.
ValueTypeAlias for the type of the elements of the array.

Remarks

#include <system/array.h>
#include <system/smart_ptr.h>

using namespace System;

void Print(const SmartPtr<Array<int32_t>> &arrayPtr)
{
  for (auto item: arrayPtr)
  {
    std::cout << item << ' ';
  }
  std::cout << std::endl;
}

int main()
{
  // Create and fill the array.
  auto arrayPtr = MakeObject<Array<int32_t>>(5, 0);
  for (auto i = 0; i < arrayPtr->get_Length(); ++i)
  {
    arrayPtr[i] = 5 - i;
  }

  // Print the array items.
  Print(arrayPtr);

  // Sort the array items by ascending.
  Array<int32_t>::Sort(arrayPtr);

  // Print the array items.
  Print(arrayPtr);

  // Print the count of the array items.
  std::cout << arrayPtr->get_Length() << std::endl;

  // Print the index of the item that equals to 4.
  std::cout << arrayPtr->IndexOf(4) << std::endl;

  // Resize the array.
  Array<int32_t>::Resize(arrayPtr, 3);

  // Print the array items.
  Print(arrayPtr);

  return 0;
}
/*
This code example produces the following output:
5 4 3 2 1
1 2 3 4 5
5
3
1 2 3
*/

See Also