CMagic
0.5.0
Portable C library of utilities and data structures
|
A sequence container representing array that can change in size. More...
#include <vector.hpp>
Public Types | |
using | value_type = T |
Type of vector elements. More... | |
using | size_type = size_t |
Type used to measure element size and position in a vector. More... | |
Public Member Functions | |
vector () | |
Constructs an empty vector with standard memory allocation. More... | |
size_type | size () const |
Returns the number of elements in the vector. More... | |
bool | empty () const |
Returns whether the vector is empty (i.e. whether its size is 0). More... | |
value_type & | operator[] (size_type pos) |
Returns a reference to the element at position pos in the vector container. More... | |
const value_type & | operator[] (size_type pos) const |
Returns a reference to the element at position pos in the vector container. More... | |
bool | push_back (const value_type &val) |
Add element at the end. More... | |
bool | push_back (value_type &&val) |
Add element at the end. More... | |
template<typename... Args> | |
bool | emplace_back (Args &&... args) |
Construct and insert element at the end. More... | |
void | pop_back () |
Delete last element. More... | |
void | clear () |
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0. More... | |
value_type * | begin () |
Return iterator to beginning. More... | |
const value_type * | begin () const |
Return iterator to beginning. More... | |
value_type * | end () |
Return iterator to end. More... | |
const value_type * | end () const |
Return iterator to end. More... | |
operator bool () const | |
Checks if the vector is properly initialized. More... | |
Static Public Member Functions | |
static vector | custom_allocation_vector () |
Constructs an empty vector using custom CMagic memory allocation from memory.h. More... | |
A sequence container representing array that can change in size.
The content forms contiguous storage location. Size can change dynamically, with storage being handled automatically by the container. Reallocations if needed happen only at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity.
using cmagic::vector< T >::size_type = size_t |
Type used to measure element size and position in a vector.
using cmagic::vector< T >::value_type = T |
Type of vector elements.
|
inline |
Constructs an empty vector with standard memory allocation.
|
inline |
Return iterator to beginning.
Returns an iterator pointing to the first element in the vector. If the container is empty, the returned iterator value shall not be dereferenced.
|
inline |
Return iterator to beginning.
Returns an iterator pointing to the first element in the vector. If the container is empty, the returned iterator value shall not be dereferenced.
|
inline |
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.
|
inlinestatic |
Constructs an empty vector using custom CMagic memory allocation from memory.h.
|
inline |
Construct and insert element at the end.
Inserts a new element at the end of the vector, right after its current last element. This new element is constructed in place using args as the arguments for its constructor. This effectively increases the container size by one, which causes an automatic reallocation of the allocated storage space if the new vector size surpasses the current vector capacity.
args | arguments forwarded to construct the new element |
|
inline |
Returns whether the vector is empty (i.e. whether its size is 0).
This function does not modify the container in any way. To clear the content of a vector, see vector::clear.
true
if the container size is 0, false
otherwise
|
inline |
Return iterator to end.
Returns an iterator referring to the past-the-end element in the vector container. The past-the-end element is the theoretical element that would follow the last element in the vector. It does not point to any element, and thus shall not be dereferenced.
|
inline |
Return iterator to end.
Returns an iterator referring to the past-the-end element in the vector container. The past-the-end element is the theoretical element that would follow the last element in the vector. It does not point to any element, and thus shall not be dereferenced.
|
inline |
Checks if the vector is properly initialized.
Example usage:
true
if vector is initialized, false
if vector allocation has failed and no operation should be made on it
|
inline |
Returns a reference to the element at position pos
in the vector container.
pos | Position of an element in the container. Notice that the first element has a position of 0 (not 1). |
|
inline |
Returns a reference to the element at position pos
in the vector container.
pos | Position of an element in the container. Notice that the first element has a position of 0 (not 1). |
|
inline |
Delete last element.
Removes the last element in the vector, effectively reducing the container size by one.
|
inline |
Add element at the end.
Adds a new element at the end of the vector, after its current last element. The content of val
is copied (or moved) to the new element. This effectively increases the container size by one, which causes an automatic reallocation of the allocated storage space if the new vector size surpasses the current vector capacity.
val | value to be copied (or moved) to the new element |
|
inline |
Add element at the end.
Adds a new element at the end of the vector, after its current last element. The content of val
is copied (or moved) to the new element. This effectively increases the container size by one, which causes an automatic reallocation of the allocated storage space if the new vector size surpasses the current vector capacity.
val | value to be copied (or moved) to the new element |
|
inline |
Returns the number of elements in the vector.
This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.