Neat Vectors  5
Hanes
Public Member Functions | Related Functions | List of all members
Vector< FUN > Class Template Reference

A (very neat) vector. More...

#include <vector.h>

Public Member Functions

 Vector ()
 Constructs an empty vector. More...
 
 Vector (const Vector< FUN > &v)
 Copy Constructor. More...
 
 ~Vector ()
 Destructor.
 
void push_back (FUN v)
 Add elements to the vector. More...
 
FUN & operator[] (const unsigned int idx)
 Reads an element of the vector. More...
 
const FUN & operator[] (const unsigned int idx) const
 Reads an element of the vector. More...
 
unsigned int length () const
 The number of items stored in the vector. More...
 
unsigned int size () const
 The size of the underlying storage. More...
 

Related Functions

(Note that these are not member functions.)

template<class FUN >
ostream & operator<< (ostream &out, const Vector< FUN > &v)
 Stream insertion operator for Vector. More...
 

Detailed Description

template<class FUN>
class Vector< FUN >

A (very neat) vector.

It's a vector. You put stuff into it, you get stuff out of it, that's about it.

Precondition
FUN must support assignment (FUN = FUN)

Constructor & Destructor Documentation

◆ Vector() [1/2]

template<class FUN >
Vector< FUN >::Vector ( )

Constructs an empty vector.

Postcondition
The underlying storage is allocated with 4 elements.

◆ Vector() [2/2]

template<class FUN >
Vector< FUN >::Vector ( const Vector< FUN > &  v)

Copy Constructor.

Postcondition
Creates a new vector with copies of elements from v and underlying storage size equal to that of v's storage.

Member Function Documentation

◆ length()

template<class FUN >
unsigned int Vector< FUN >::length ( ) const

The number of items stored in the vector.

Returns
the number of items stored in the vector.

◆ operator[]() [1/2]

template<class FUN >
FUN & Vector< FUN >::operator[] ( const unsigned int  idx)

Reads an element of the vector.

Parameters
idxthe index of the element to read.
Returns
The element at position idx is returned.
Precondition
idx is within the range [0, length()).
Exceptions
std::invalid_argumentis thrown if idx is out of range.

◆ operator[]() [2/2]

template<class FUN >
const FUN & Vector< FUN >::operator[] ( const unsigned int  idx) const

Reads an element of the vector.

Parameters
idxthe index of the element to read.
Returns
The element at position idx is returned.
Precondition
idx is within the range [0, length()).
Exceptions
std::invalid_argumentis thrown if idx is out of range.

◆ push_back()

template<class FUN >
void Vector< FUN >::push_back ( FUN  v)

Add elements to the vector.

Precondition
None.
Postcondition
The element is added to the end of the vector. If need be, the size of the underlying storage is doubled.

◆ size()

template<class FUN >
unsigned int Vector< FUN >::size ( ) const

The size of the underlying storage.

Returns
the size of the underlying storage.

Friends And Related Function Documentation

◆ operator<<()

template<class FUN >
ostream & operator<< ( ostream &  out,
const Vector< FUN > &  v 
)
related

Stream insertion operator for Vector.

Precondition
Stream insertion operator is defined for FUN.
Postcondition
The contents of the vector are printed to the ouptut stream.
Returns
the modified output stream.

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