// Prog: vector.h // definition of the class ifmp::vector namespace ifmp { template class vector { public: typedef T* iterator; typedef const T* const_iterator; // default constructor // POST: *this is an empty vector vector (); // POST: *this is a vector of size s vector (const unsigned int s); // POST: *this is a vector of size s, elements initialized with val vector (const unsigned int s, const T& val); // copy constructor vector (const vector& v); // assignment operator vector& operator= (const vector& v); // destructor ~vector (); // POST: *this was emptied void clear (); // POST: returns the size of the vector unsigned int size () const; // POST: returns the capacity of the vector unsigned int capacity () const; // POST: element with value val is appended to *this, // capacity of *this was increased if necessary void push_back (const T& val); // POST: returns a iterator pointing to the first element iterator begin(); const_iterator begin() const; // POST: returns a past-the-end iterator iterator end(); const_iterator end() const; // PRE: n < size() // POST: returns a reference to the n-th element T& operator[] (unsigned int n); // PRE: n < size() // POST: returns a const reference to the n-th element const T& operator[] (unsigned int n) const; private: iterator begin_; iterator end_; iterator end_of_memory_; // PRE: [begin, end) is a valid range, [to,to+ end-begin) points to // allocated memory and is not overlapping with [begin, end) // POST: elements in [begin, end) are copied to the range // [to, to+end-begin), returns an iterator pointing to the // end of the destination range iterator copy(iterator begin, iterator end, iterator to); // POST: *this has twice as much capacity as before or at least 1 void increase_capacity(); // POST: *this has capacity at least c void increase_capacity(unsigned int c); }; } // include the implementation of the class ifmp::vector #include "vector.cpp"