|
@@ -68,8 +68,8 @@ namespace Core {
|
|
List copy;
|
|
List copy;
|
|
CORE_RETURN_ERROR(allocate(copy.data, n));
|
|
CORE_RETURN_ERROR(allocate(copy.data, n));
|
|
copy.capacity = n;
|
|
copy.capacity = n;
|
|
- for(int i = 0; i < length; i++) {
|
|
+ for(T& t : *this) {
|
|
- copy.unsafeAdd(Core::move(data[i]));
|
|
+ copy.unsafeAdd(Core::move(t));
|
|
}
|
|
}
|
|
swap(copy);
|
|
swap(copy);
|
|
return Error::NONE;
|
|
return Error::NONE;
|
|
@@ -92,7 +92,7 @@ namespace Core {
|
|
check_return Error resize(int n, const T& t) {
|
|
check_return Error resize(int n, const T& t) {
|
|
if(length < n) {
|
|
if(length < n) {
|
|
CORE_RETURN_ERROR(reserve(n));
|
|
CORE_RETURN_ERROR(reserve(n));
|
|
- for(int i = length; i < n; i++) {
|
|
+ for(int i = n - length; i != 0; i--) {
|
|
unsafeAdd(t);
|
|
unsafeAdd(t);
|
|
}
|
|
}
|
|
} else if(length > n) {
|
|
} else if(length > n) {
|
|
@@ -107,7 +107,7 @@ namespace Core {
|
|
check_return Error resize(int n) {
|
|
check_return Error resize(int n) {
|
|
if(length < n) {
|
|
if(length < n) {
|
|
CORE_RETURN_ERROR(reserve(n));
|
|
CORE_RETURN_ERROR(reserve(n));
|
|
- for(int i = length; i < n; i++) {
|
|
+ for(int i = n - length; i != 0; i--) {
|
|
unsafeAdd(T());
|
|
unsafeAdd(T());
|
|
}
|
|
}
|
|
} else if(length > n) {
|
|
} else if(length > n) {
|
|
@@ -172,10 +172,14 @@ namespace Core {
|
|
return Error::INVALID_INDEX;
|
|
return Error::INVALID_INDEX;
|
|
}
|
|
}
|
|
length--;
|
|
length--;
|
|
- for(int i = index; i < length; i++) {
|
|
+ T* currentT = begin() + index;
|
|
- data[i] = Core::move(data[i + 1]);
|
|
+ T* endT = end();
|
|
|
|
+ while(currentT != endT) {
|
|
|
|
+ T* nextT = currentT + 1;
|
|
|
|
+ *currentT = Core::move(*nextT);
|
|
|
|
+ currentT = nextT;
|
|
}
|
|
}
|
|
- data[length].~T();
|
|
+ endT->~T();
|
|
return Error::NONE;
|
|
return Error::NONE;
|
|
}
|
|
}
|
|
|
|
|