#include <array.h>
Public Types | |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef T | value_type |
typedef uint | size_type |
Public Member Functions | |
Array (size_type count) | |
Array (size_type count, const T &value) | |
Array (const Array< T > &array) | |
Array (Array< T > &&old) | |
Array (std::initializer_list< T > list) | |
template<class T2 > | |
Array (const T2 *array, size_type n) | |
template<class... TArgs> | |
void | emplace (const_iterator pos, TArgs &&... args) |
template<class... TArgs> | |
void | emplace_back (TArgs &&...args) |
void | push_back (const T &element) |
void | push_back (T &&element) |
void | push_back (const Array< T > &array) |
void | pop_back () |
const T * | data () const |
T * | data () |
T & | front () |
const T & | front () const |
T & | back () |
const T & | back () const |
void | insert_at (size_type idx, const T &element) |
void | insert_at (size_type idx, const Array< T > &array) |
void | insert (iterator pos, const T &element) |
T | remove_at (size_type idx) |
T & | operator[] (size_type idx) |
const T & | operator[] (size_type idx) const |
Array< T > & | operator= (const Array< T > &array) |
Array & | operator= (Array< T > &&old) |
size_type | size () const |
void | clear () |
iterator | erase (iterator pos) |
iterator | erase (iterator first, iterator last) |
bool | empty () const |
bool | operator== (const Array< T > &other) const |
bool | operator!= (const Array< T > &other) const |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
void | reserve (size_type newCapacity) |
void | resize (size_type newSize) |
void | resize (size_type newSize, const T value) |
void | assign (const_iterator first, const_iterator last) |
void | swap (Array &arr) |
Protected Member Functions | |
void | allocCapacity (size_type capacity) |
void | freeStorage (T *storage, const size_type elements) |
iterator | insert_aux (iterator pos, const_iterator first, const_iterator last) |
Static Protected Member Functions | |
static size_type | roundUpCapacity (size_type capacity) |
Protected Attributes | |
size_type | _capacity |
size_type | _size |
T * | _storage |
This class implements a dynamically sized container, which can be accessed similarly to a regular C++ array. Accessing elements is performed in constant time (like with plain arrays). In addition, you can append, insert, and remove entries (this is the 'dynamic' part). In general, doing that takes time proportional to the number of elements in the array.
The container class closest to this in the C++ standard library is std::vector. However, there are some differences.
typedef T* Common::Array< T >::iterator |
Array iterator.
typedef const T* Common::Array< T >::const_iterator |
Const-qualified array iterator.
typedef T Common::Array< T >::value_type |
Value type of the array.
typedef uint Common::Array< T >::size_type |
Size type of the array.
|
inlineexplicit |
Construct an array with count
default-inserted instances of T
. No copies are made.
|
inline |
Construct an array with count
copies of elements with value value
.
|
inline |
Construct an array as a copy of the given array
.
|
inline |
Construct an array as a copy of the given array using the C++11 move semantic.
|
inline |
Construct an array using list initialization. For example:
constructs an array with 3 elements whose values are 1, 7, and 42 respectively.
|
inline |
Construct an array by copying data from a regular array.
|
inline |
Construct an element into a position in the array.
|
inline |
Construct an element to the end of the array.
|
inline |
Append an element to the end of the array.
|
inline |
Append an element to the end of the array.
|
inline |
Append an element to the end of the array.
|
inline |
Remove the last element of the array.
|
inline |
Return a pointer to the underlying memory serving as element storage.
|
inline |
Return a pointer to the underlying memory serving as element storage.
|
inline |
Return a reference to the first element of the array.
|
inline |
Return a reference to the first element of the array.
|
inline |
Return a reference to the last element of the array.
|
inline |
Return a reference to the last element of the array.
|
inline |
Insert an element into the array at the given position.
|
inline |
Insert copies of all the elements from the given array into this array at the given position.
|
inline |
Insert an element before pos
.
|
inline |
Remove an element at the given position from the array and return the value of that element.
|
inline |
Return a reference to the element at the given position in the array.
|
inline |
Return a const reference to the element at the given position in the array.
|
inline |
Assign the given array
to this array.
|
inline |
Assign the given array to this array using the C++11 move semantic.
|
inline |
Return the size of the array.
|
inline |
Clear the array of all its elements.
|
inline |
Erase the element at pos
position and return an iterator pointing to the next element in the array.
|
inline |
Erase the elements from first
to last
and return an iterator pointing to the next element in the array.
|
inline |
Check whether the array is empty.
|
inline |
Check whether two arrays are identical.
|
inline |
Check if two arrays are different.
|
inline |
Return an iterator pointing to the first element in the array.
|
inline |
Return an iterator pointing past the last element in the array.
|
inline |
Return a const iterator pointing to the first element in the array.
|
inline |
Return a const iterator pointing past the last element in the array.
|
inline |
Reserve enough memory in the array so that it can store at least the given number of elements. The current content of the array is not modified.
|
inline |
Change the size of the array.
|
inline |
Change the size of the array and initialize new elements that exceed the current array's size with copies of value.
|
inline |
Assign to this array the elements between the given iterators from another array, from first
included to last
excluded.
|
inlinestaticprotected |
Round up capacity to the next power of 2. A minimal capacity of 8 is used.
|
inlineprotected |
Allocate a specific capacity for the array.
|
inlineprotected |
Free the storage used by the array.
|
inlineprotected |
Insert a range of elements coming from this or another array. Unlike std::vector::insert, this method does not accept arbitrary iterators, mainly because our iterator system is seriously limited and does not distinguish between input iterators, output iterators, forward iterators, or random access iterators.
So, we simply restrict to Array iterators. Extending this to arbitrary random access iterators would be trivial.
Moreover, this method does not handle all cases of inserting a subrange of an array into itself; this is why it is private for now.
|
protected |
Maximum number of elements the array can hold.
|
protected |
How many elements the array holds.
|
protected |
Memory used for element storage.