Commit 59ba350f authored by topjohnwu's avatar topjohnwu

Fix copy and move assigments of Array

parent 803c5377
......@@ -67,17 +67,30 @@ public:
T* _node;
};
T& operator = (const T& a) {
Array &operator=(const Array& a) {
delete [] _data;
_data = nullptr;
_size = a._size;
_capacity = a._capacity;
if (_capacity) {
_data = new T[_capacity];
for(int i = 0; i < _size; ++i)
_data[i] = utils::move(a[i]);
_data[i] = a[i];
}
return *this;
}
Array &operator=(Array&& a) {
delete [] _data;
_size = a._size;
_capacity = a._capacity;
_data = a._data;
a._size = 0;
a._capacity = 0;
a._data = nullptr;
return *this;
}
iterator begin() const { return iterator(_data); }
iterator end() const { return iterator(_data + _size); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment