Why does D not have generics?
Guillaume Piolat
first.last at gmail.com
Wed Jan 13 08:33:58 UTC 2021
On Tuesday, 12 January 2021 at 14:45:36 UTC, Adam D. Ruppe wrote:
>
> The benefit of this is you have almost zero compile time cost
> and runtime cost comparable to any other class. It avoids
> template bloat in codegen that can be very significant in D.
>
> I'd love to have it as an option in D as well. There's a lot of
> types that can use identical runtime code and just change
> types. Not just classes, but like integer types too can be
> identical and merged, const/immutable/shared/etc can be
> identical and merged, and even other things with cast(void*)
> can do it.
>
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.
More information about the Digitalmars-d
mailing list