Why Templates?
Walter Bright
newshound at digitalmars.com
Sun Mar 5 23:57:08 PST 2006
"John C" <johnch_atms at hotmail.com> wrote in message
news:dufl8l$14au$1 at digitaldaemon.com...
> "Walter Bright" <newshound at digitalmars.com> wrote in message
> news:dufcpn$p1n$2 at digitaldaemon.com...
>> 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.
>From what I read, C# generics do not instantiate a new routine for every set
of argument types, it implements *one* routine which handles them all via
casting.
More information about the Digitalmars-d
mailing list