ASL
|
An Array is a contiguous and resizable array of any type of elements.
It can be used as a normal fixed-size array. The length()
property holds its size:
Elements can be appended at the end at any moment or the array resized or cleared:
And you can concatenate the elements as a string if they are convertible to String:
#include <Array.h>
Public Member Functions | |
Array () | |
Creates an empty array. | |
Array (int n) | |
Creates an array of n elements. | |
Array (const T *p, int n) | |
Creates an array of n elements and copies them from the pointer p. | |
Array (int n, const T &x) | |
Creates an array of n elements and gives them the value x. | |
template<class K > | |
Array< K > | with () const |
Returns a copy of this array with all element converted to another type. | |
int | length () const |
Returns the number of elements in the array. | |
Array & | reserve (int m) |
Reserves space for m elements without increasing actual length (to make appending faster) | |
Array & | resize (int m) |
Resizes the array to m elements; up to m existing elements are preserved. | |
void | clear () |
Removes all elements in the array. | |
operator const T * () const | |
Returns a pointer to the base of the array. More... | |
operator T* () | |
Returns a pointer to the base of the array. More... | |
const T * | ptr () const |
Returns a pointer to the first element. More... | |
T * | ptr () |
Returns a pointer to the first element. More... | |
T * | data () |
Returns a pointer to the first element. | |
const T * | data () const |
Returns a pointer to the first element. | |
bool | operator== (const Array &b) const |
Tests for equality of all elements of both arrays. | |
const T & | operator[] (int i) const |
Returns the element at index i. | |
T & | operator[] (int i) |
Returns the element at index i. | |
const T & | last () const |
Returns a reference to the last element. | |
T & | last () |
Returns a reference to the last element. | |
int | indexOf (const T &x, int j=0) const |
Returns the index of the first element with value x; The search starts at position j; The value -1 is returned if no such element is found. | |
bool | contains (const T &x) const |
Returns true if the array contains an element equal to x. | |
Array & | dup () |
Makes this array independent of others. | |
Array | clone () const |
Returns an independent copy of this array. | |
void | copy (const Array &b) |
Copies another array's contents into this array. | |
void | copy (const T *p, int n) |
Copies n elements pointed to by p (the array is resized to n) | |
Array & | operator= (const Array &b) |
Assigns array b into this array by reference. | |
Array & | operator<< (const T &x) |
Adds element x at the end of the array. | |
Array & | operator, (const T &x) |
The same as << , useful to create pseudo-array-literals. | |
Array & | remove (int i, int n=1) |
Removes n elements (1 be default) starting at position i. | |
bool | removeOne (const T &x, int i0=0) |
Removes the first element with value x starting at index i0; Returns true if an element was found and removed. | |
Array & | insert (int k, const T &x) |
Inserts x at position k. | |
Array | reversed () const |
Returns the elements of the array in reversed order. | |
Array | slice (int i1, int i2=0) const |
Returns a section of the array, from element i1 up to but not including element i2; If i2 is omitted the subarray will take elements up te the last. | |
Array & | append (const Array &b) |
Adds all elements from array b at the end of the array. | |
Array & | append (const T *p, int n) |
Adds n elements from array pointed by p at the end of this array. | |
Array | concat (const Array &b) const |
Returns the concatenation of this array and b. | |
Array | operator| (const Array &b) const |
Returns the concatenation of this array and b. | |
Array & | sort () |
Sorts the array using the elements' < operator "in place". | |
template<class Less > | |
Array & | sort (Less f) |
Sorts the array using the elements' < operator "in place". | |
template<class F > | |
Array & | sortBy (F f, bool ascending=true) |
Sorts the array by the elements' f comparable property (in ascending order by default) | |
String | join (const String &sep) const |
Returns a string representation of the array, formed by joining its elements with the given separator string sep; The elements need to be convertible to String. | |
template<class F > | |
Array | map (F f) const |
Returns an array formed by applying a function to each item. | |
template<class K , class F > | |
Array< K > | map_ (F f) const |
Returns an array of another type formed by applying a function to each item. | |
template<class F > | |
Array | filter (F f) const |
Returns an array containing the items in this array satisfying a condition. | |
template<class F > | |
Array & | removeIf (F f) |
Removes items that meet a predicate. | |
Array & | removeLast () |
Removes the last item in the array. | |
operator const T * | ( | ) | const |
Returns a pointer to the base of the array.
operator T* | ( | ) |
Returns a pointer to the base of the array.
|
inline |
Returns a pointer to the first element.
|
inline |
Returns a pointer to the first element.