Array

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>

Template parameters

ParameterDescription
TType of elements of an array

Methods

MethodDescription
void 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.
iterator begin()Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end().
const_iterator 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 int BinarySearch(System::ArrayPtr<T>, const T&)Performs binary search in the sorted array.
static int BinarySearch(System::ArrayPtr<T>, const Y&, const SharedPtr<Collections::Generic::IComparer<Z>>&)NOT IMPLEMENTED.
const_iterator 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().
const_iterator 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.
void Clear() overrideNot supported because the array represented by the current object is read-only.
static void Clear(const ArrayPtr<Type>&, int, int)Replaces count values starting at the startIndex index in the specified array with default values.
ArrayPtr<T> Clone()Clones the array.
bool Contains(const T&) const overrideDetermines if the specified item is in the array.
static ArrayPtr<OutputType> 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 ArrayPtr<OutputType> 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 void Copy(const ArrayPtr<SrcType>&, const ArrayPtr<DstType>&, int64_t)Copies the specified number of elements from the source array to the destination array.
static void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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 void 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.
void 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.
void 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.
void 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.
void 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.
void 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.
int Count() constReturns a number that represents the total number of all elements in all dimensions of the array.
const_reverse_iterator 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().
const_reverse_iterator 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.
vector_t& data()Returns a reference to the internal data structure used to store the array elements.
const vector_t& data() constReturns a constant reference to the internal data structure used to store the array elements.
vector_t::pointer data_ptr()Returns a raw pointer to the beginning of the memory buffer where the array elements are stored.
const UnderlyingType * data_ptr() constReturns a constant raw pointer to the beginning of the memory buffer where the array elements are stored.
iterator 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.
const_iterator 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.
virtual bool Equals(ptr)Compares objects using C# Object.Equals semantics.
static std::enable_if<IsSmartPtr<T1>::value&&IsSmartPtr<T2>::value, bool>::type Equals(T1 const&, T2 const&)Compares reference type objects in C# style.
static std::enable_if<!IsSmartPtr<T1>::value&&!IsSmartPtr<T2>::value, bool>::type Equals(T1 const&, T2 const&)Compares value type objects in C# style.
static bool Equals(float const&, float const&)Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN.
static bool Equals(double const&, double const&)Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN.
static bool Exists(ArrayPtr<T>, std::function<bool(T)>)Determines if the specified Array object contains an element that satisfies requirements of the specified predicate.
virtual bool FastCast(const Details::FastRttiBase&, void **) constFor internal purposes only.
static T 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 System::ArrayPtr<T> FindAll(System::ArrayPtr<T>, System::Predicate<T>)Retrieves all the elements that match the conditions defined by the specified predicate.
static int 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 void ForEach(const ArrayPtr<T>&, System::Action<T>)Performs specified action on each element of the specified array.
int get_Count() const overrideReturns the size of the array.
bool get_IsFixedSize()Checks whether the collection is of fixed size.
bool get_IsReadOnly() const overrideIndicates whether the array is read-only.
int32_t get_Length() constReturns 32-bit integer that represents the total number of all elements in all dimensions of the array.
int64_t get_LongLength() constReturns 64-bit integer that represents the total number of all elements in all dimensions of the array.
int32_t get_Rank() constNOT IMPLEMENTED.
SharedPtr<Object> get_SyncRoot() constGets the object the collection is being synchronized through.
Detail::SmartPtrCounter * GetCounter()Gets reference counter data structure associated with the object.
EnumeratorPtr GetEnumerator() overrideReturns a pointer to Enumerator object that provides IEnumerator interface to elements of the array represented by the current object.
virtual int32_t GetHashCode() constAnalog of C# Object.GetHashCode() method. Enables hashing of custom objects.
int GetLength(int)Returns the number of elements in the specified dimension.
int64_t GetLongLength(int)Returns the number of elements in the specified dimension as 64-bit integer.
int GetLowerBound(int) constReturns the lower bound of the specified dimension.
size_t GetSizeTLength() constReturns an std::size_t variable that represents the total number of all elements in all dimensions of the array.
virtual const TypeInfo& GetType() constGets actual type of object. Analog of C# System.Object.GetType() call.
int GetUpperBound(int)Returns the upper bound of the specified dimension.
ICollection()Default constructor.
ICollection(const ICollection&)Copy constructor.
ICollection(ICollection&&)Move constructor.
T idx_get(int) const overrideReturns the item at the specified index.
void idx_set(int, T) overrideSets the specified value as the item of the array at the specified index.
int IndexOf(const T&) const overrideDetermines the index of the first occurrence of the specified item in the array.
static int IndexOf(const ArrayPtr<ArrayType>&, const ValueType&)Determines the index of the first occurrence of specified item in the array.
static int 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 int 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.
ArrayPtr<T> Init(const T)Fills the array represented by the current object with the values from the specified array.
void Initialize()Fills the array with the default constructed objects of type T.
void Insert(int, const T&) overrideNot supported because array represented by the current object is read-only.
virtual bool Is(const TypeInfo&) constCheck if object represents an instance of type described by targetType. Analog of C# ‘is’ operator.
static int 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 int 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 int LastIndexOf(const ArrayPtr<ArrayType>&, const ValueType&)Determines the index of the last occurrence of the specified item in the array.
bool LINQ_All(std::function<bool(T)>)Determines whether all elements of a sequence satisfy a condition.
bool LINQ_Any()Determines whether a sequence contains any elements.
bool LINQ_Any(std::function<bool(T)>)Determines whether any element of a sequence exists or satisfies a condition.
SharedPtr<IEnumerable<ResultType>> LINQ_Cast()Casts the elements to the specified type.
SharedPtr<IEnumerable<Result>> LINQ_Cast()
SharedPtr<IEnumerable<T>> LINQ_Concat(SharedPtr<IEnumerable<T>>)Concatenates two sequences.
bool LINQ_Contains(T)Determines if a sequence contains a specified value.
int LINQ_Count()Returns the number of elements in the sequence (calculated via direct counting).
int LINQ_Count(const Func<T, bool>&)Returns the number of elements in the sequence that satisfy the specified condition.
T LINQ_ElementAt(int)Returns the element at a specified index in a sequence.
T LINQ_First()Returns the first element of a sequence.
T LINQ_First(const Func<T, bool>&)Returns the first element of a sequence that satisfy the specified condition.
T LINQ_FirstOrDefault()Returns the first element of a sequence, or a default value if the sequence is empty.
T LINQ_FirstOrDefault(std::function<bool(T)>)Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
System::SharedPtr<IEnumerable<System::SharedPtr<System::Linq::IGrouping<Key, T>>>> LINQ_GroupBy(System::Func<T, Key>)Groups the elements of a sequence.
SharedPtr<IEnumerable<SharedPtr<System::Linq::IGrouping<Key, Source>>>> LINQ_GroupBy(System::Func<Source, Key>)
T LINQ_Last()Returns the last element of a sequence.
T LINQ_LastOrDefault()Returns the last element of a sequence, or a default value if the sequence is empty.
SharedPtr<IEnumerable<ResultType>> LINQ_OfType()Filters the elements of the sequence based on the specified type.
SharedPtr<IEnumerable<Result>> LINQ_OfType()
SharedPtr<IEnumerable<T>> LINQ_OrderBy(const Func<T, Key>&)Sorts the elements of a sequence in ascending order according to the key values selected by keySelector.
SharedPtr<IEnumerable<Source>> LINQ_OrderBy(const Func<Source, Key>&)
SharedPtr<IEnumerable<T>> LINQ_OrderByDescending(const Func<T, Key>&)Sorts the elements of a sequence in descending order according to the key values selected by keySelector.
SharedPtr<IEnumerable<Source>> LINQ_OrderByDescending(const Func<Source, Key>&)
SharedPtr<IEnumerable<ResultType>> LINQ_Select(const Func<T, ResultType>&)Transforms elements of a sequence.
SharedPtr<IEnumerable<ResultType>> LINQ_Select(const Func<T, int32_t, ResultType>&)Transforms each element of a sequence into a new form by incorporating the element’s index.
SharedPtr<IEnumerable<Result>> LINQ_Select(const Func<Source, Result>&)
SharedPtr<IEnumerable<Result>> LINQ_Select(const Func<Source, int32_t, Result>&)
SharedPtr<IEnumerable<ResultType>> LINQ_SelectMany(const Func<T, SharedPtr<IEnumerable<ResultType>>>&)Projects each element of a sequence and combines the resulting sequences into one sequence.
SharedPtr<IEnumerable<Result>> LINQ_SelectMany(const Func<Source, SharedPtr<IEnumerable<Result>>>&)
System::ArrayPtr<T> LINQ_ToArray()Creates an array from a sequence.
SharedPtr<List<T>> LINQ_ToList()Creates a List from a sequence.
SharedPtr<IEnumerable<T>> LINQ_Where(std::function<bool(T)>)Filters a sequence based on the specified predicate.
void Lock()Implements C# lock() statement locking. Call directly or use LockContext sentry object.
UnderlyingType Max() constFinds the largest element in the array using operator<() to compare elements.
virtual ptr MemberwiseClone() constAnalog of C# Object.MemberwiseClone() method. Enables cloning custom types.
UnderlyingType Min() constFinds the smallest element in the array using operator<() to compare elements.
Object()Creates object. Initializes all internal data structures.
Object(Object const&)Copy constructor. Doesn’t copy anything, really, just initializes new object and enables copy constructing subclasses.
Object& operator=(Object const&)Assignment operator. Doesn’t copy anything, really, just initializes new object and enables copy constructing subclasses.
ICollection& operator=(ICollection&&)Move assignment operator.
ICollection& operator=(const ICollection&)Move assignment operator.
UnderlyingType& operator[](int)Returns an item at the specified index.
UnderlyingType const& operator[](int) constReturns an item at the specified index.
reverse_iterator 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().
const_reverse_iterator 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().
static bool ReferenceEquals(ptr const&, ptr const&)Compares objects by reference.
static std::enable_if<!IsSmartPtr<T>::value, bool>::type ReferenceEquals(T const&, T const&)Compares objects by reference.
static std::enable_if<!IsSmartPtr<T>::value, bool>::type ReferenceEquals(T const&, std::nullptr_t)Reference-compares value type object with nullptr.
bool ReferenceEquals(String const&, std::nullptr_t)Specialization of Object::ReferenceEquals for case of string and nullptr.
bool ReferenceEquals(String const&, String const&)Specialization of Object::ReferenceEquals for case of strings.
bool Remove(const T&) overrideNot supported because the array represented by the current object is read-only.
void RemoveAt(int) overrideNot supported because array represented by the current object is read-only.
int RemovedSharedRefs(int)Decreases shared reference count by specified value.
reverse_iterator 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.
const_reverse_iterator 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 void Resize(ArrayPtr<Type>&, int)Changes the size of the specified array to the specified value or crates new array with specified size.
static void Reverse(const ArrayPtr<Type>&)Reverses elements in the specified array.
static void Reverse(const ArrayPtr<Type>&, int, int)Reverses a range of elements in the specified array.
void SetTemplateWeakPtr(uint32_t) overrideMakes array treat stored pointers as weak (if applicable).
void SetValue(const T&, int)Sets value of the element at specified index.
int SharedCount() constGets current value of shared reference counter.
Object * SharedRefAdded()Increments shared reference count. Shouldn’t be called directly; instead, use smart pointers or ThisProtector.
int SharedRefRemovedSafe()Decrements and returns shared reference count. Shouldn’t be called directly; instead, use smart pointers or ThisProtector.
static void Sort(const ArrayPtr<Type>&)Sorts elements in the specified array using default comparer.
static void Sort(const ArrayPtr<Type>&, int, int)Sorts a range of elements in the specified array using default comparer.
static void Sort(const ArrayPtr<Type>&, const SharedPtr<System::Collections::Generic::IComparer<T>>&)Sorts elements in the specified array using specified comparer.
static void Sort(const ArrayPtr<Type>&, const SharedPtr<System::Collections::Generic::IComparer<Y>>&)NOT IMPLEMENTED.
static void 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 void 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.
virtual String ToString() constAnalog of C# Object.ToString() method. Enables converting custom objects to string.
static bool TrueForAll(System::ArrayPtr<T>, System::Predicate<T>)Determines whether all elements in the specified array satisfy the conditions defined by specified predicate.
static const TypeInfo& Type()Implements C# typeof(System.Object) construct.
void Unlock()Implements C# lock() statement unlocking. Call directly or use LockContext sentry object.
System::Details::VirtualizedIteratorBase<T> * virtualizeBeginConstIterator() const overrideGets the implementation of begin const iterator for the current container.
System::Details::VirtualizedIteratorBase<T> * virtualizeBeginIterator() overrideGets the implementation of begin iterator for the current container.
System::Details::VirtualizedIteratorBase<T> * virtualizeEndConstIterator() const overrideGets the implementation of end const iterator for the current container.
System::Details::VirtualizedIteratorBase<T> * virtualizeEndIterator() overrideGets the implementation of end iterator for the current container.
Detail::SmartPtrCounter * WeakRefAdded()Increments weak reference count. Shouldn’t be called directly; instead, use smart pointers or ThisProtector.
void WeakRefRemoved()Decrements weak reference count. Shouldn’t be called directly; instead, use smart pointers or ThisProtector.
virtual ~ICollection()Destructor.
virtual ~Object()Destroys object. Frees all internal data structures.

Typedefs

TypedefDescription
ValueTypeAlias for the type of the elements of the array.
UnderlyingTypeAlias for the type used to represent each element of the array.
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.
const_iteratorConst iterator type.
reverse_iteratorReverse iterator type.
const_reverse_iteratorConst reverse iterator type.

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