#ifndef __CS427527_VECTOR_HPP__ #define __CS427527_VECTOR_HPP__ #include #include #include #include #include #include "task.hpp" using Task = todo::Task; namespace cs427_527 { /** * An array-based list. * * @param T a copy-constructable and -assignable type with an output * operator << that works with std::ostream */ template class Vector { public: /** * Creates an empty vector. */ Vector(); /** * Creates a copy of the given vector. * * @param toCopy the vector to copy */ Vector(const Vector& toCopy); /** * Moves the contents of the given vector to a new one. * * @param toMove the vector to move contents from */ Vector(Vector&& toMove); /** * Destroys this vector. */ ~Vector(); /** * Overwrites the contents of this vector with the contents of the given * vector. * * @param rhs the vector to copy * @return a reference to this vector */ Vector& operator=(const Vector& rhs); /** * Overwrites the contents of this vector by moving the contents of the * given vector to it. * * @param rhs the vector to copy * @return a reference to this vector */ Vector& operator=(Vector&& rhs); /** * Returns the number of elements in this vector. * * @return the number of elements in this vector */ int size() const; /** * Adds the given item to the end of this vector. * * @param item the item to add */ void push_back(const T& item); /** * Returns a printable representation of this vector. * * @return a printable representation of this vector */ std::string toString() const; private: const int INITIAL_CAPACITY = 2; void deallocate(); void copy(const Vector& toCopy); void move(Vector& toMove); void embiggen(); int capacity; int count; T *elements; }; /** * Outputs a printable representation of this vector to the given stream. * * @param os the stream to write to * @param v the vector to output * @return a reference to os */ template std::ostream& operator<<(std::ostream& os, const Vector& v); } #include "vector.cpp" #endif