Skip to content

Commit 6f22c06

Browse files
committed
Improved ArrayList. (#319)
1 parent 89eab48 commit 6f22c06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ArrayList.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,20 @@ class ArrayList {
7070
return -1;
7171
}
7272
int lastIndexOf(E element) { return lastIndexOfInRange(element, 0, _size); }
73-
ArrayList<E> copy() { return ArrayList<E>(this); }
73+
ArrayList<E> copy() { return ArrayList<E>(reinterpret_cast<size_t>(this)); }
7474
ArrayList<E> operator+(const ArrayList<E> &other) { return add(other); }
7575
ArrayList<E> &operator=(const ArrayList<E> &other) {
7676
if (this != &other) {
7777
ensureCapacityInternal(other._capacity);
78-
memcpy(_array, other._array, _size * sizeof(E));
78+
if (other._size > 0)
79+
memcpy(_array, other._array, _size * sizeof(E));
7980
}
8081
return *this;
8182
}
83+
E *begin() { return _array; }
84+
E *end() { return _array + _size; }
85+
const E *begin() const { return _array; }
86+
const E *end() const { return _array + _size; }
8287
};
8388

8489

0 commit comments

Comments
 (0)