How does D's templated functions implementation differ from generics in C#/Java?
doob at me.com
Sat Aug 8 08:19:48 UTC 2020
On 2020-08-07 23:03, aberba wrote:
> Syntactically they look the same (although D's can do more things) so
> I'm trying to understand how why in D it's called template but in
> languages like C#/Java they're generics.
> I guess I have fair understanding of D's code generation but isn't it
> same as what what is available in those languages too? How are the
> implementation different?
Objective-C recently added support for generics. It uses the same
approach as Java, type erasure. Basically the only reason why this was
added is to make the Swift APIs better and more type safe.
Swift also has quite an interesting implementation of generics. IIRC
correctly it supports both a more Java like implementation where you
only get one instantiation and a more D/C++ like implementation where
the compiler generates one instantiation per type.
This is supposed to give the best of both worlds. Little binary bloat
and high performance.
More information about the Digitalmars-d-learn