Why does D not have generics?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Jan 15 11:58:13 UTC 2021


On Wednesday, 13 January 2021 at 08:33:58 UTC, Guillaume Piolat 
wrote:
> A practice I've heard from game industry people was to 
> instantiate template with void* to avoid duplicate template 
> instantiation, and then cast at boundaries. Typically for 
> containers.

Yes, that is what I suggested also. I implemented it yesterday 
for deque, stack, etc, all using the same memory layout for 64 
bit values (pointers, ints, doubles etc).

What makes it cool is that you can construct datastructures that 
use the same ranges code, despite having different types.

However, it cannot be done without very negative effects on 
precise collection, I think. So it is a bad fit for D, since it 
is GC based, and precise collection is the future...

So, trashed it. (I translated it to C++ instead... :-P)




More information about the Digitalmars-d mailing list