Some bugfixes and added templated member functions\! (even for templated objs\!) In this vein, added in_place and map functions to vector\!

This commit is contained in:
Nathan Braswell
2015-05-27 00:58:33 -04:00
parent 88bab7f0d7
commit 85834789e4
9 changed files with 120 additions and 32 deletions

View File

@@ -26,6 +26,13 @@ obj vector<T> (Destructable) {
delete<T>(data);
}
fun clone(): vector<T> {
var newVec.construct(size): vector<T>
for (var i = 0; i < size; i++;)
newVec.set(i, data[i])
return newVec
}
fun resize(newSize: int): bool {
var newData: T* = new<T>(newSize);
if (!newData)
@@ -67,5 +74,15 @@ obj vector<T> (Destructable) {
resize(size*2);
data[size-1] = dataIn;
}
fun in_place(func: fun(T):T):void {
for (var i = 0; i < size; i++;)
data[i] = func(data[i])
}
fun map<U>(func: fun(T):U):vector<U> {
var newVec.construct(size): vector<U>
for (var i = 0; i < size; i++;)
newVec.set(i, func(data[i]))
return newVec
}
};