This commit is contained in:
Felix Brendel
2020-10-27 02:36:33 +01:00
parent f53506a723
commit b766118a1f
+30 -2
View File
@@ -1,5 +1,6 @@
#pragma once
#include <stdlib.h>
#include <initializer_list>
#include "types.hpp"
template <typename type>
@@ -16,10 +17,9 @@ struct Array_List {
void dealloc() {
free(data);
data = 0;
data = nullptr;
}
void clear() {
next_index = 0;
}
@@ -68,6 +68,16 @@ struct Array_List {
return data[index];
}
static Array_List<type> alloc_from(std::initializer_list<type> l) {
Array_List<type> ret;
ret.alloc(l.size());
for (auto e : l) {
ret.append(e);
}
ret.auto_free = true;
return ret;
}
void _merge(u32 start, u32 mid, u32 end) {
u32 start2 = mid + 1;
@@ -137,3 +147,21 @@ struct Array_List {
return middle;
}
};
template <typename type>
struct Auto_Array_List : public Array_List<type> {
Auto_Array_List() = default;
Auto_Array_List(std::initializer_list<type> l) {
this->alloc(l.size());
for (type e : l) {
this->append(e);
}
}
~Auto_Array_List() {
free(this->data);
this->data = nullptr;
}
};