I’ve already noticed that C# generics are quite different from C++ templates. I’ve read this question and answers to it and got a basic understanding of what the difference is.
However I don’t get the reason for that design difference. I mean C++ was already quite developed when C# was being designed. What was suboptimal in C++ templates that C# developers did not clone C++ templates but instead rolled in generics that are so massively different?
What can generics do what C++ templates can’t? In what are C# generics better than C++ templates? What’s the reason for designing C# generics behaving differently from C++ templates?
The reason is that one ARE TEMPLATES the other are not. Sounds redundant? Partially because you ask a question oalong “why is a car different from a plane”.
Templates are a very complex mechanism and most of the compelxity is rarely used. I think you don’t really know what templates can do – only the 25% of C++ templates people use every day. This is the main problem – they are too comlpex. Hard for the compiler.
So Generics are supposed to capture a different approach for the most common use of templates, which is generic general types (no specialization, for example).
Nothing.
The fact that C++ generics are hardly mastered by anyone and a terrible thing to implement correctly for the compiler, while mostly going unused.