__if_comp__ __C__ __simple_passthrough__ """ #include """ /* we have a template versions so we don't have to cast (because we don't have that yet) */ template |T*| malloc(|int| size) { |T*| memPtr = 0; __if_comp__ __C__ { __simple_passthrough__ """ memPtr = malloc(size); """ } return memPtr; } template |void| free(|T*| memPtr) { __if_comp__ __C__ { __simple_passthrough__ """ free(memPtr); """ } } template |int| sizeof() { |int| result = 0; |T| testObj; __if_comp__ __C__ { __simple_passthrough__ """ result = sizeof(testObj); """ } return result; } template |T*| new(|int| count) { return malloc( sizeof() * count ); } template |T*| new() { return new(1); } /* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ template |void| delete(|T*| toDelete, |int| itemCount) { delete(toDelete); } /* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */ template |void| delete(|T*| toDelete, |int| itemCount) { for (|int| i = 0; i < itemCount; i++;) toDelete[i].destruct(); delete(toDelete); } /* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ template |void| delete(|T*| toDelete) { free(toDelete); } template |void| delete(|T*| toDelete) { toDelete->destruct(); free(toDelete); }