// Prog: vector.h // definition of the class ifmp::vector namespace ifmp { class vector { public: typedef int* iterator; typedef const int* 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 int& 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 int& val); // POST: returns an 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 int& operator[] (const unsigned int n); // PRE: n < size() // POST: returns a const reference to the n-th element const int& operator[] (const 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 (); // PRE: c >= size() // POST: *this has capacity at least c void increase_capacity (const unsigned int c); }; } // end namespace