DSC Engine
All Classes Files Functions Variables Typedefs
Public Member Functions | List of all members
DSC::Vector< T > Class Template Reference

Generic dynamic vector. More...

#include <vector.hpp>

Public Member Functions

 Vector (int size=0)
 
 Vector (const Vector< T > &vector)
 
 Vector (Vector< T > &&vector)
 
template<typename... Args>
 Vector (T _first, Args... args)
 
Vector< T > & operator= (Vector< T > &&vector)
 
Vector< T > & operator= (const Vector< T > &vector)
 
void clear ()
 Sets all the elements in the vector to their default value determined by their type. More...
 
void reset ()
 Sets the vector to its initial state

 
void resize (int new_size)
 Changes vector's number of elements. More...
 
void push_back (const T &item)
 Adds new element to the end of the vector. More...
 
T & back ()
 Gets the last element in vector. More...
 
int index_of (const T &item) const
 Finds the position of an item in the vector. More...
 
bool remove (const T &item)
 Removes the first occurence of an element from the vector. More...
 
void remove_at (int index)
 Removes the element at a given position. More...
 
int size () const
 Gets the vector length. More...
 
T & operator[] (int index)
 Random access index operator. More...
 
const T & operator[] (int index) const
 Random access index operator. More...
 
const T & get_at (int index) const
 Gets element at a certain index. More...
 

Detailed Description

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

Generic dynamic vector.

Template Parameters
Ttype of contained items

Member Function Documentation

◆ back()

template<typename T >
T & DSC::Vector< T >::back

Gets the last element in vector.

Parameters
[output]The element on the last position in vector

Error is raised is the vector is empty

◆ clear()

template<typename T >
void DSC::Vector< T >::clear

Sets all the elements in the vector to their default value determined by their type.

Not to be confused with reset(), which also sets the vector to its initials size

◆ get_at()

template<typename T >
const T & DSC::Vector< T >::get_at ( int  index) const

Gets element at a certain index.

Parameters
[in]indexPosition in vector
Returns
Element at the specified position

Range checks are performed only in debug mode.

◆ index_of()

template<typename T >
int DSC::Vector< T >::index_of ( const T &  item) const

Finds the position of an item in the vector.

Parameters
[in]itemItem to be found
Returns
position of the first occurence of the item if it was found, -1 otherwise

◆ operator[]() [1/2]

template<typename T >
T & DSC::Vector< T >::operator[] ( int  index)

Random access index operator.

Parameters
[in]indexPosition in vector
Returns
Element at the specified position

Range checks are performed only in debug mode.

◆ operator[]() [2/2]

template<typename T >
const T & DSC::Vector< T >::operator[] ( int  index) const

Random access index operator.

Parameters
[in]indexPosition in vector
Returns
Element at the specified position

Can be used as an lvalue e.g. v[i] = my_T_Element;

Range checks are performed only in debug mode.

◆ push_back()

template<typename T >
void DSC::Vector< T >::push_back ( const T &  item)

Adds new element to the end of the vector.

Parameters
[in]itemElement to be added

◆ remove()

template<typename T >
bool DSC::Vector< T >::remove ( const T &  item)

Removes the first occurence of an element from the vector.

Parameters
[in]itemElement to be removed
Returns
true if removal was successful, false otherwise (item not found)

◆ remove_at()

template<typename T >
void DSC::Vector< T >::remove_at ( int  index)

Removes the element at a given position.

Parameters
[in]indexPosition of the element to remove

Range checks are performed only in debug mode.

◆ resize()

template<typename T >
void DSC::Vector< T >::resize ( int  new_size)

Changes vector's number of elements.

Parameters
[in]new_capNew vector size

If the vector becomes smaller after this operation, the left-out elements are discarded

◆ size()

template<typename T >
int DSC::Vector< T >::size

Gets the vector length.

Returns
Number of elements in vector

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