C/C++实现
template<typename Object>
class Vector
{
private:
int Size;
int Capacity;
Object * objects;
public:
explicit Vector(int initSize = 0);
Vector(const Vector& rhs);
Vector(Vector&& rhs);
Vector&operator=(const Vector&rhs)
{
Vector copy = rhs;
swap(*this, copy);
return *this;
}
Vector&operator=(Vector&&rhs)
{
swap(Size, rhs.Size);
swap(Capacity, rhs.Capacity);
swap(objects, rhs.objects);
return *this;
}
Object& operator[](int index)
{
if (index >= 0 && index < Size)
return objects[index];
else
throw "index out of bounds";
}
const Object&operator[](int index)const
{
if (index >= 0 && index < Size)
return objects[index];
else
throw "index out of bounds";
}
~Vector() {
delete[]objects; }
public:
static const int SPARE_CAPACITY = 16;
class const_iterator
{
protected:
Object * current;
const Vector<Object>*theVect;
const_iterator(Object *