Templated methods work now, even explicit instantiation (along with implicit)

This commit is contained in:
Nathan Braswell
2016-02-20 02:36:35 -05:00
parent c5dda4b7ec
commit b073d5806b
8 changed files with 112 additions and 212 deletions

View File

@@ -1,6 +1,3 @@
import set
import map
__if_comp__ __C__ simple_passthrough """
#include <stdlib.h>
"""
@@ -103,31 +100,6 @@ fun maybe_destruct<T(Object)>(it:*T):void {
it->destruct()
}
// a function that allows the safe deletion of recursive and complicated data structures
fun safe_recursive_delete<T>(first: *T, addingFunc: fun(*T): set::set<*T>) {
var toDelete = set::set<*T>()
var next = set::set(first)
while (toDelete != next) {
toDelete = next
toDelete.for_each( fun(it: *T) next.add(addingFunc(it)); )
}
toDelete.for_each( fun(it: *T) delete(it); )
}
// a function that allows the safe cloning of recursive and complicated data structures
// cloneing func is the func that does the cloning, it takes in a recursive clone function and
// a register clone function
fun safe_recursive_clone<T>(first: *T, cloningFunc: fun(*T, fun(*T):*T, fun(*T):void): void): *T {
var rec_map = map::map<*T,*T>()
// can't do type infrence if you need the type inside the expression...
var rec_it: fun(*T):*T = fun(it: *T): *T {
if (!rec_map.contains_key(it))
cloningFunc(it, rec_it, fun(cloned: *T) { rec_map[it] = cloned; })
return rec_map[it]
}
return rec_it(first)
}
obj shared_ptr<T> (Object){
var data: *T;
var refCount: int;
@@ -191,4 +163,3 @@ obj shared_ptr<T> (Object){
}; //end shared_ptr class