Why Templates?

John C johnch_atms at hotmail.com
Sun Mar 5 13:29:51 PST 2006


"Walter Bright" <newshound at digitalmars.com> wrote in message 
news:dufcpn$p1n$2 at digitaldaemon.com...
>
> "Ivan Senji" <ivan.senji_REMOVE_ at _THIS__gmail.com> wrote in message 
> news:duf72h$f40$1 at digitaldaemon.com...
>> Maybe so, but I see a common Object base class a hack to solve many 
>> problems that are simple and efficient to solve with templates. For 
>> example containers. Containers in Java(before templates)-style and 
>> C#(before templates)-style are nothing but inefficient hacks.
>
> Technically, Java and C# implement generics, not templates. C++ and D 
> implement templates, not generics.
>
> What's the difference? One way to think about it is generics are handled 
> at run time (by casting), templates at compile time.

I'm sure you're wrong about C#'s implementation using casts. Java generics 
do erase the type information and cast everything to an object. But the CLR 
was reworked to support generics so List<int> remains a list of ints until 
it's instantiated at runtime. 





More information about the Digitalmars-d mailing list