TinyLib 0.1.1
Loading...
Searching...
No Matches
tl::Vector< T > Class Template Reference

#include <Vector.h>

Public Member Functions

 Vector ()
 Create a new empty vector.
 
 ~Vector ()
 Clean up vector data.
 
void push (const T &value)
 Adds a new element to the end of the vector.
 
pop ()
 Get the last element and remove it from the vector.
 
T & operator[] (size_t index)
 Write access to elements.
 
const T & operator[] (size_t index) const
 Read access to elements.
 
void resize (size_t new_capacity)
 Resize the max capacity for this vector.
 
void clear ()
 Clear vector size for most vector methods.
 
size_t getSize () const
 Get the size of this vector.
 
size_t getCapacity () const
 Get the capacity of this vector.
 
void insert (size_t pos, const T &value)
 Insert an element anywhere in the vector.
 
void erase (size_t pos)
 Delete an element and shift the rest of the vector to fit.
 
T * begin ()
 
T * end ()
 
const T * begin () const
 
const T * end () const
 

Detailed Description

template<typename T>
class tl::Vector< T >

Definition at line 7 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector()

template<typename T >
tl::Vector< T >::Vector ( )

Create a new empty vector.

Template Parameters
TWhat type this vector will hold.

Definition at line 38 of file Vector.h.

◆ ~Vector()

template<typename T >
tl::Vector< T >::~Vector ( )

Clean up vector data.

Template Parameters
THow much memory is freed depends on the data type you used.

Definition at line 49 of file Vector.h.

Member Function Documentation

◆ begin() [1/2]

template<typename T >
T * tl::Vector< T >::begin ( )
inline

Definition at line 23 of file Vector.h.

◆ begin() [2/2]

template<typename T >
const T * tl::Vector< T >::begin ( ) const
inline

Definition at line 25 of file Vector.h.

◆ clear()

template<typename T >
void tl::Vector< T >::clear ( )

Clear vector size for most vector methods.

Template Parameters
TMust match the type for this vector.

Definition at line 132 of file Vector.h.

◆ end() [1/2]

template<typename T >
T * tl::Vector< T >::end ( )
inline

Definition at line 24 of file Vector.h.

◆ end() [2/2]

template<typename T >
const T * tl::Vector< T >::end ( ) const
inline

Definition at line 26 of file Vector.h.

◆ erase()

template<typename T >
void tl::Vector< T >::erase ( size_t pos)

Delete an element and shift the rest of the vector to fit.

Template Parameters
TT Must match the type for this vector.
Parameters
posIndex of element to delete.

When you erase an element, everything to the right of that element will be shifted left in the vector to not leave an empty space.

Definition at line 187 of file Vector.h.

◆ getCapacity()

template<typename T >
size_t tl::Vector< T >::getCapacity ( ) const

Get the capacity of this vector.

Template Parameters
TMust match the type for this vector.
Returns
Current capacity of vector.

Capacity is how big the internal array is for this vector. Good to check to make sure you don't go out of bounds with [].

Definition at line 157 of file Vector.h.

◆ getSize()

template<typename T >
size_t tl::Vector< T >::getSize ( ) const

Get the size of this vector.

Template Parameters
TMust match the type for this vector.
Returns
Current size of vector.

Size is based on how many elements actually exist in the vector.

Definition at line 144 of file Vector.h.

◆ insert()

template<typename T >
void tl::Vector< T >::insert ( size_t pos,
const T & value )

Insert an element anywhere in the vector.

Template Parameters
TT Must match the type for this vector.
Parameters
posPosition to insert element at.
valueElement to insert.

Definition at line 168 of file Vector.h.

◆ operator[]() [1/2]

template<typename T >
T & tl::Vector< T >::operator[] ( size_t index)

Write access to elements.

Template Parameters
TMust match the type for this vector.
Parameters
indexElement to overwrite.
Returns
Reference to element to overwrite.

Definition at line 90 of file Vector.h.

◆ operator[]() [2/2]

template<typename T >
const T & tl::Vector< T >::operator[] ( size_t index) const

Read access to elements.

Template Parameters
TMust match the type for this vector.
Parameters
indexElement to read.
Returns
Reference to element to read.

Definition at line 101 of file Vector.h.

◆ pop()

template<typename T >
T tl::Vector< T >::pop ( )

Get the last element and remove it from the vector.

Template Parameters
TMust match the type for this vector.
Returns
The removed element.

Definition at line 75 of file Vector.h.

◆ push()

template<typename T >
void tl::Vector< T >::push ( const T & value)

Adds a new element to the end of the vector.

Template Parameters
TMust match the type for this vector.
Parameters
valueElement to add.

Definition at line 62 of file Vector.h.

◆ resize()

template<typename T >
void tl::Vector< T >::resize ( size_t new_capacity)

Resize the max capacity for this vector.

Template Parameters
TMust match the type for this vector.
Parameters
new_capacityNew capacity.

If you don't use push or pop, you can also manually resize the vector with this, and can then access elements within capacity using [].

Definition at line 114 of file Vector.h.


The documentation for this class was generated from the following file: