mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Implement copy constructor and assignment operator to the vector.
This commit is contained in:
parent
17ed2f9a89
commit
d3856fdfe5
@ -35,9 +35,12 @@ public:
|
|||||||
const T &operator[](const int index) const;
|
const T &operator[](const int index) const;
|
||||||
T &operator[](const int index);
|
T &operator[](const int index);
|
||||||
|
|
||||||
|
Vector &operator=(const Vector &other);
|
||||||
|
|
||||||
Vector();
|
Vector();
|
||||||
Vector(int prealloc);
|
Vector(int prealloc);
|
||||||
Vector(int prealloc, int grow_by);
|
Vector(int prealloc, int grow_by);
|
||||||
|
Vector(const Vector &other);
|
||||||
~Vector();
|
~Vector();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -221,6 +224,15 @@ T &Vector<T>::operator[](const int index) {
|
|||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Vector<T> &Vector<T>::operator=(const Vector<T> &other) {
|
||||||
|
resize(0);
|
||||||
|
ensure_capacity(other.size());
|
||||||
|
append_array(other);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Vector<T>::Vector() {
|
Vector<T>::Vector() {
|
||||||
_data = nullptr;
|
_data = nullptr;
|
||||||
@ -249,6 +261,21 @@ Vector<T>::Vector(int prealloc, int grow_by) {
|
|||||||
ensure_capacity(prealloc);
|
ensure_capacity(prealloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Vector<T>::Vector(const Vector<T> &other) {
|
||||||
|
_actual_size = other._actual_size;
|
||||||
|
_size = other._size;
|
||||||
|
_grow_by = other._grow_by;
|
||||||
|
|
||||||
|
if (other._data) {
|
||||||
|
_data = new T[_actual_size];
|
||||||
|
|
||||||
|
for (int i = 0; i < _size; ++i) {
|
||||||
|
_data[i] = other._data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Vector<T>::~Vector() {
|
Vector<T>::~Vector() {
|
||||||
if (_data) {
|
if (_data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user