Templates lots of newbie qs.

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Mar 8 10:12:29 PST 2007


"Chris Warwick" <sp at m.me.not> wrote in message 
news:espgo1$16ge$1 at digitalmars.com...
>
> So templated functions dont need to be inside a template block? You only 
> need a template block when you want to group a bunch of stuff together 
> into one template, so the whole lot can be created in one go?

Right.  The nice thing about templating functions individually is that then 
you don't need to specify the template part of the name; instead of typing 
"templateName!(int).functionName(params)" you just have to type 
"functionName!(int)(params)", or with IFTI....

>
> IFTI?

...you can just type "functionName(params)".

IFTI stands for "Implicit Function Template Instantiation."  When you write 
a templated function:

T func(T)(T val)
{
    return val;
}

You don't want to have to type out:

func!(int)(4);
func!(char[])("hi");

So IFTI can implicitly determine what T should be by looking at the 
parameter list:

func(4); // T is determined to be int
func("hello"); // T is determined to be char[]

It's a very useful feature.

> It's surprised me how very often, even with more advanced features, the D 
> syntax seems to be exactly what you would expect it to be. A very good 
> sign imo, it seems so intuative straight of the bat.

Well, that's why D is the language everyone should be using!  :) 




More information about the Digitalmars-d-learn mailing list