Templated methods work now, even explicit instantiation (along with implicit)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user