Data Structures & Algorithms in C++
Goodrich, Tamassia, Mount and Goldwasser
Loading...
Searching...
No Matches
Data Structures | Public Member Functions
dsac::array::Vector< T > Class Template Reference

dynamically sized array, as simplified version of std::vector More...

#include <vector.h>

Collaboration diagram for dsac::array::Vector< T >:
Collaboration graph

Data Structures

class  const_iterator
 
class  iterator
 

Public Member Functions

 Vector ()
 Constructs an empty vector.
 
int capacity () const
 
int size () const
 
bool empty () const
 
const T & operator[] (int i) const
 
T & operator[] (int i)
 
const T & at (int i) const
 
T & at (int i)
 
const T & front () const
 
T & front ()
 
const T & back () const
 
T & back ()
 
void push_back (const T &elem)
 
void pop_back ()
 Removes an element from the end of the vector.
 
void insert (int i, const T &elem)
 
void erase (int i)
 
void reserve (int minimum)
 
 Vector (const Vector &other)
 Copy constructor.
 
Vectoroperator= (const Vector &other)
 Copy assignment.
 
 Vector (Vector &&other)
 Move constructor.
 
Vectoroperator= (Vector &&other)
 Move assignment.
 
 ~Vector ()
 Destructor.
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
iterator insert (iterator it, const T &elem)
 
iterator erase (iterator it)
 

Detailed Description

template<typename T>
class dsac::array::Vector< T >

dynamically sized array, as simplified version of std::vector

Constructor & Destructor Documentation

◆ Vector() [1/3]

template<typename T >
dsac::array::Vector< T >::Vector ( )
inline

Constructs an empty vector.

◆ Vector() [2/3]

template<typename T >
dsac::array::Vector< T >::Vector ( const Vector< T > &  other)
inline

Copy constructor.

◆ Vector() [3/3]

template<typename T >
dsac::array::Vector< T >::Vector ( Vector< T > &&  other)
inline

Move constructor.

◆ ~Vector()

template<typename T >
dsac::array::Vector< T >::~Vector ( )
inline

Destructor.

Member Function Documentation

◆ at() [1/2]

template<typename T >
T & dsac::array::Vector< T >::at ( int  i)
inline

Returns reference to the element at index i; raises out_of_range exception with invalid index

Parameters
iindex of desired element
Returns
element at index i
Exceptions
out_of_rangeexception if index is invalid for current vector

◆ at() [2/2]

template<typename T >
const T & dsac::array::Vector< T >::at ( int  i) const
inline

Returns const reference to the element at index i; raises out_of_range exception with invalid index

Parameters
iindex of desired element
Returns
element at index i
Exceptions
out_of_rangeexception if index is invalid for current vector

◆ back() [1/2]

template<typename T >
T & dsac::array::Vector< T >::back ( )
inline

Returns a live reference to the last element; behavior is undefined if vector is empty

Returns
reference to last element

◆ back() [2/2]

template<typename T >
const T & dsac::array::Vector< T >::back ( ) const
inline

Returns a const reference to the last element; behavior is undefined if vector is empty

Returns
reference to last element

◆ begin() [1/2]

template<typename T >
iterator dsac::array::Vector< T >::begin ( )
inline

◆ begin() [2/2]

template<typename T >
const_iterator dsac::array::Vector< T >::begin ( ) const
inline

◆ capacity()

template<typename T >
int dsac::array::Vector< T >::capacity ( ) const
inline

Returns the current capacity of the underlying array

Returns
the size of the underlying array

◆ empty()

template<typename T >
bool dsac::array::Vector< T >::empty ( ) const
inline

Tests whether the vector is empty.

Returns
true if the vector is empty, false otherwise

◆ end() [1/2]

template<typename T >
iterator dsac::array::Vector< T >::end ( )
inline

◆ end() [2/2]

template<typename T >
const_iterator dsac::array::Vector< T >::end ( ) const
inline

◆ erase() [1/2]

template<typename T >
void dsac::array::Vector< T >::erase ( int  i)
inline

Removes element at index i; behavior is undefined if i is out of bounds

Parameters
iindex of element to be removed

◆ erase() [2/2]

template<typename T >
iterator dsac::array::Vector< T >::erase ( iterator  it)
inline

Removes the element at the given iterator position

Parameters
ititerator defining the position of element to be removed
Returns
iterator just beyond the removed element
Here is the call graph for this function:

◆ front() [1/2]

template<typename T >
T & dsac::array::Vector< T >::front ( )
inline

Returns a live reference to the first element; behavior is undefined if vector is empty

Returns
reference to first element

◆ front() [2/2]

template<typename T >
const T & dsac::array::Vector< T >::front ( ) const
inline

Returns a const reference to the first element; behavior is undefined if vector is empty

Returns
reference to first element

◆ insert() [1/2]

template<typename T >
void dsac::array::Vector< T >::insert ( int  i,
const T &  elem 
)
inline

Inserts an element at index i; behavior is undefined if i is out of bounds

Parameters
iindex at which new element should be placed
elemthe new element
Here is the call graph for this function:

◆ insert() [2/2]

template<typename T >
iterator dsac::array::Vector< T >::insert ( iterator  it,
const T &  elem 
)
inline

Inserts an element immediately before the given iterator position

Parameters
ititerator defining the insertion position
elemthe new element
Returns
iterator of newly inserted element
Here is the call graph for this function:

◆ operator=() [1/2]

template<typename T >
Vector & dsac::array::Vector< T >::operator= ( const Vector< T > &  other)
inline

Copy assignment.

◆ operator=() [2/2]

template<typename T >
Vector & dsac::array::Vector< T >::operator= ( Vector< T > &&  other)
inline

Move assignment.

◆ operator[]() [1/2]

template<typename T >
T & dsac::array::Vector< T >::operator[] ( int  i)
inline

Returns reference to the element at index i; behavior is undefined if i is out of bounds

Parameters
iindex of desired element
Returns
element at index i

◆ operator[]() [2/2]

template<typename T >
const T & dsac::array::Vector< T >::operator[] ( int  i) const
inline

Returns const reference to the element at index i; behavior is undefined if i is out of bounds

Parameters
iindex of desired element
Returns
element at index i

◆ pop_back()

template<typename T >
void dsac::array::Vector< T >::pop_back ( )
inline

Removes an element from the end of the vector.

◆ push_back()

template<typename T >
void dsac::array::Vector< T >::push_back ( const T &  elem)
inline

Inserts an element at end of the vector

Parameters
elemthe new element
Here is the call graph for this function:

◆ reserve()

template<typename T >
void dsac::array::Vector< T >::reserve ( int  minimum)
inline

Requests that the vector capacity be at least as large as the indicated capacity The function has no effect if the current capacity is already larger than the parameter.

Parameters
capthe minimum capacity after the operation

◆ size()

template<typename T >
int dsac::array::Vector< T >::size ( ) const
inline

Returns the number of elements stored

Returns
the number of elements stored

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