Templates lots of newbie qs.
Chris Warwick
sp at m.me.not
Thu Mar 8 12:06:53 PST 2007
"Chris Warwick" <sp at m.me.not> wrote in message
news:espqa6$1r76$1 at digitalmars.com...
>
> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
> news:espjmc$1d51$1 at digitalmars.com...
>> "Chris Warwick" <sp at m.me.not> wrote in message
>> news:espgo1$16ge$1 at digitalmars.com...
>>>
>>> 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.
>
> So say you have the following...
>
> int indexOf(T)(T[] arr, T item)
> {
> // search for and return index
> }
>
> class Foo()
> {
> Bar[] fitems;
> int indexOf(Bar b)
> {
> fitems.indexOf(b); // <--- name clash
should be:
return fitems.indexOf(b);
More information about the Digitalmars-d-learn
mailing list