template<class T, class TSize = SizeT>
class evo::Array< T, TSize >
Dynamic array container with similar interface to List.
- Template Parameters
-
T | Item type to use |
TSize | Size type to use for size/index values (must be unsigned integer) – default: SizeT |
- Features
- Items are stored sequentially in contiguous memory – random access uses constant time
- Advanced methods have "adv" prefix – these allow some intrusive control
- No memory allocated by new empty array
- No extra capacity allocation, sharing, or slicing like List
C++11:
- Range-based for loop – see STL Compatibility
Array<int> arr;
for (auto num : arr) {
}
- Initialization lists
Array<int> arr = {1, 2, 3};
- Move semantics
- Iterators
- Constructors
- Read Access
- Modifiers
- Advanced
- Example
int main() {
for (int i = 0; i < 5; ++i)
array[i] = i;
c.
out <<
"Value: " << *iter <<
NL;
return 0;
}
Output:
Item: 1
Item: 2
Item: 3
Item: 4
Item: 5
|
| Array () |
| Default constructor sets as null. More...
|
|
| Array (const ValEmpty &val) |
| Constructor sets as empty but not null. More...
|
|
| Array (const ThisType &src) |
| Copy constructor. More...
|
|
| Array (const T *data, Size size) |
| Copy constructor. More...
|
|
| Array (std::initializer_list< T > init) |
| Sequence constructor (C++11). More...
|
|
| Array (ThisType &&src) |
| Move constructor (C++11). More...
|
|
| ~Array () |
| Destructor to free used memory. More...
|
|
ThisType & | add (const Item &item) |
| Append new item. More...
|
|
ThisType & | addnew (Size size=1) |
| Append new items. More...
|
|
ThisType & | advResize (Size size) |
| Advanced: Resize while preserving existing data, POD items not initialized (modifier). More...
|
|
const T & | advRing (Key index) const |
| Advanced: Get ring-buffer item at position (const). More...
|
|
T & | advRing (Key index) |
| Advanced: Get ring-buffer item at position (mutable). More...
|
|
const ThisType & | asconst () const |
| Explicitly use a const reference to this. More...
|
|
IterM | begin () |
| Get iterator at first item (mutable). More...
|
|
Iter | begin () const |
| Get iterator at first item (const). More...
|
|
Iter | cbegin () const |
| Get iterator at first item (const). More...
|
|
Iter | cend () const |
| Get iterator at end (const). More...
|
|
ThisType & | clear () |
| Clear by removing all items. More...
|
|
int | compare (const ThisType &data) const |
| Comparison. More...
|
|
const T * | data () const |
| Get data pointer (const). More...
|
|
T * | data () |
| Get data pointer (mutable). More...
|
|
bool | empty () const |
| Get whether empty. More...
|
|
IterM | end () |
| Get iterator at end. More...
|
|
Iter | end () const |
| Get iterator at end. More...
|
|
bool | ends (const T &item) const |
| Check if ends with given item. More...
|
|
bool | ends (const T *items, Size size) const |
| Check if ends with given items. More...
|
|
ThisType & | fill (const T &item, Key index=0, Size size=ALL) |
| Fill using item (modifier). More...
|
|
const T * | first () const |
| Get first item (const). More...
|
|
T * | first () |
| Get first item (mutable). More...
|
|
ulong | hash (ulong seed=0) const |
| Get data hash value for whole array. More...
|
|
Key | iend (Size offset=0) const |
| Get index from last item using offset. More...
|
|
Size | insert (Key index, const Item &item) |
| Insert new item. More...
|
|
Size | insertnew (Key index, Size size=1) |
| Insert new items. More...
|
|
const T & | item (Key index) const |
| Get item at position (const). More...
|
|
T & | item (Key index) |
| Get item at position (mutable). More...
|
|
const T * | last () const |
| Get last item (const). More...
|
|
T * | last () |
| Get last item (mutable). More...
|
|
bool | null () const |
| Get whether null. More...
|
|
bool | operator!= (const ThisType &data) const |
| Inequality operator. More...
|
|
ThisType & | operator= (ThisType &&src) |
| Move assignment operator (C++11). More...
|
|
ThisType & | operator= (const ThisType &src) |
| Assignment operator. More...
|
|
ThisType & | operator= (const ValNull &) |
| Assignment operator to set as null and empty. More...
|
|
ThisType & | operator= (const ValEmpty &) |
| Assignment operator to set as empty but not null. More...
|
|
bool | operator== (const ThisType &data) const |
| Equality operator. More...
|
|
const T & | operator[] (Key index) const |
| Get item at position (const). More...
|
|
T & | operator[] (Key index) |
| Get item at position (mutable). More...
|
|
Size | remove (Key index, Size size=1) |
| Remove items. More...
|
|
ThisType & | resize (Size size) |
| Resize while preserving existing data (modifier). More...
|
|
ThisType & | resize2 (Size size) |
| Resize as power of 2 while preserving existing data (modifier). More...
|
|
const T & | ring (Key index) const |
| Get ring-buffer item at position (const). More...
|
|
T & | ring (Key index) |
| Get ring-buffer item at position (mutable). More...
|
|
ThisType & | set () |
| Set as null and empty. More...
|
|
ThisType & | set (const ThisType &src) |
| Set as copy of another array. More...
|
|
ThisType & | set (const T *data, Size size) |
| Set as copy using data pointer. More...
|
|
ThisType & | setempty () |
| Set as empty but not null. More...
|
|
bool | shared () const |
| Get whether shared (false). More...
|
|
Size | size () const |
| Get size. More...
|
|
bool | starts (const T &item) const |
| Check if starts with given item. More...
|
|
bool | starts (const T *items, Size size) const |
| Check if starts with given items. More...
|
|
void | swap (ThisType &array) |
| Swap with another array. More...
|
|
ThisType & | unshare () |
| Make data unique – no-op. More...
|
|