www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Function template type parameter inference

reply csci <csci nowhere.com> writes:
I noticed in the D spec it states that

"Function template type parameters that are to be implicitly deduced may not
have
specializations"

However, the following code works:

void Foo(T : double)(T t) { writefln("%f",t+2); }
...
Foo(5.5);

I was wondering if this is behavior that can be relied upon, or if it may change
in the future? Or am I misreading things?
Jul 19 2011
parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Wed, 20 Jul 2011 07:52:58 +0200, csci <csci nowhere.com> wrote:

 I noticed in the D spec it states that

 "Function template type parameters that are to be implicitly deduced may  
 not have
 specializations"

 However, the following code works:

 void Foo(T : double)(T t) { writefln("%f",t+2); }
 ...
 Foo(5.5);

 I was wondering if this is behavior that can be relied upon, or if it  
 may change
 in the future? Or am I misreading things?

It would very much seem you are correct in your interpretation. I question however, the validity of that part of the spec. In short, it works now, and I see no reason for that not to work. -- Simen
Jul 20 2011