__if_comp__ __C__ __simple_passthrough__ """ #include """ char* nullPtr = 0; char* malloc(int size) { char* memPtr = nullPtr; __if_comp__ __C__ { __simple_passthrough__ """ memPtr = malloc(size); """ } return memPtr; } void free(char* memPtr) { __if_comp__ __C__ { __simple_passthrough__ """ free(memPtr); """ } } /* we have a template version so we don't have to cast */ 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); } template void delete(T* toDelete, int itemCount) { for (int i = 0; i < itemDestructCount; 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) { if (destruct) toDelete->destruct(); free(toDelete); }