array (native)


Methods (WJ)

  • T random() -- Gets a random element from the array.

Methods (native)

  • uint length() const -- Returns the length of the array.
  • void resize(uint) -- Sets the new length of the array.
  • void reverse() -- Reverses the order of the elements in the array.
  • void insertAt(uint index, const T& in value)
  • void insertAt(uint index, const array<T>& arr) -- Inserts a new element, or another array of elements, into the array at the specified index.
  • void insertLast(const T& in) -- Appends an element at the end of the array.
  • void removeAt(uint index) -- Removes the element at the specified index.
  • void removeLast() -- Removes the last element of the array.
  • void removeRange(uint start, uint count) -- Removes count elements starting from start.
  • void sortAsc()
  • void sortAsc(uint startAt, uint count) -- Sorts the elements in the array in ascending order. For object types, this will use the type's opCmp method.
    The second variant will sort only the elements starting at index startAt and the following count elements.
  • void sortDesc()
  • void sortDesc(uint startAt, uint count) -- These does the same thing as sortAsc except sorts the elements in descending order.
  • void sort(const less &in compareFunc, uint startAt = 0, uint count = uint(-1)) -- This method takes as input a callback function to use for comparing two elements when sorting the array.
  • int find(const T& in)
  • int find(uint startAt, const T& in) -- These will return the index of the first element that has the same value as the wanted value.
  • int findByRef(const T& in)
  • int findByRef(uint startAt, const T& in) -- These will search for a matching address. These are especially useful for arrays of handles where specific instances of objects are desired, and not just objects that happen to have equal value. If no match is found the methods will return a negative value.
  • uint size() const
  • bool empty() const
  • void push_back(const T&in)
  • void pop_back()
  • void insert(uint index, const T&in value)
  • void insert(uint index, const array<T>& arr)
  • void erase(uint)
  • void reserve(uint length)

Declaration

array<int> a;
array<string> s;
array<CBaseEntity@> ents;
array<MyClassName@> cn;
array<int> a, b, c;
array<Foo@> d;
array<int> a;                               // A zero-length array of integers
array<int> b(3);                            // An array of integers with 3 elements
array<int> c(3, 1);                         // An array of integers with 3 elements, all set to 1 by default
array<int> d = {5,6,7};                     // An array of integers with 3 elements with specific values
array<array<int>> a;                        // An empty array of arrays of integers
array<array<int>> b = {{1,2},{3,4}}         // A 2 by 2 array with initialized values
array<array<int>> c(10, array<int>(10));    // A 10 by 10 array of integers with uninitialized values