Why does this need factory functions? Just translate it to D - no reason to cross between C++ <=> D with this code.