A tutorial on D templates
Philippe Sigaud
philippe.sigaud at gmail.com
Sat Jan 14 00:07:56 PST 2012
>> On 13/01/12 10:48 PM, DNewbie wrote:
>> > I can't understand it. Why would someone need template programming. What problem does template solve?
Well read on and see :-)
Peter:
>> Suppose you want to write a function to get the minimum of two integers.
>> It's easy:
>
> Oh.. I see.
> Thank you everybody.
And that's the first, more visible part of templates, a bit like
generics in Java.
Template are incomplete pieces of code with left-empty 'slots' which
you can fill at compile-time to decide what code will be compiled.
You can generate entire functions / class hierarchies or nicely
crafted-for-your-need code / pre-computed-by-the-compiler code with
templates.
Philippe
More information about the Digitalmars-d-learn
mailing list