Why does D not have generics?

Paul Backus snarwin at gmail.com
Tue Jan 12 17:52:16 UTC 2021


On Tuesday, 12 January 2021 at 17:43:39 UTC, Ola Fosheim Grøstad 
wrote:
> But you can do that in C++ to some extent. You can remove 
> members from a declaration, even though they are present in the 
> definition. Thanks to header files and reinterpret casting. 
> There is a lot of stuff you can do in C++ (but not really 
> recommended).

You can do it in D too, if you use an interface or a type-erasure 
library like Atila's tardy. But it requires additional runtime 
overhead compared to the loosely-checked template version. In 
Rust, on the other hand, you get strict type checking of generic 
code with zero overhead at runtime.


More information about the Digitalmars-d mailing list