2024-04-23 21:51:04 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-01-19 11:58:47 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2024-04-23 21:51:04 +02:00
|
|
|
namespace std {
|
2024-10-12 16:16:32 +02:00
|
|
|
template <class T> class vector {
|
2024-04-23 21:51:04 +02:00
|
|
|
public:
|
2025-01-19 11:58:47 +01:00
|
|
|
T *mElements;
|
|
|
|
|
int mSize;
|
|
|
|
|
int mCapacity;
|
|
|
|
|
|
|
|
|
|
~vector() {
|
|
|
|
|
if (mElements != NULL) {
|
|
|
|
|
decrease_size(mSize);
|
|
|
|
|
delete mElements;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void push_back(T &value) {
|
|
|
|
|
get_new_capacity(1);
|
|
|
|
|
append_back(1, &value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T *erase(T *first, T *last) {
|
|
|
|
|
if (first != last) {
|
|
|
|
|
int bytesToMove = (int) mElements + mSize * sizeof(T) - (int) last;
|
|
|
|
|
memmove(first, last, bytesToMove);
|
|
|
|
|
mSize -= (int) last - (int) first;
|
|
|
|
|
}
|
|
|
|
|
return first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void decrease_size(int amount);
|
|
|
|
|
|
|
|
|
|
int get_new_capacity(int growth);
|
|
|
|
|
|
|
|
|
|
void append_back(int length, T *items);
|
2024-04-23 21:51:04 +02:00
|
|
|
};
|
2024-10-12 16:16:32 +02:00
|
|
|
} // namespace std
|