Function pointer argument to function template

BCS BCS at pathlink.com
Tue May 30 14:47:54 PDT 2006


Kirk McDonald wrote:
[...]
> 
> Simple enough. But I want to deduce the return type of this function 
> pointer, and make it the default value of a second template parameter.
> 
> template Bar(T, U=<something>) {
>     U Bar(T t) {
>         return t();
>     }
> }
> 

I don't know if this is possible, however if it is and DMD stays true to 
form it will have a oddity, consider


  template Bar(T, U=<something>) {
      U Bar(T t) {
          return t(1.234567789);
      }

float 	foo(float i)	{ return i; }
double 	foo(double i)	{ return cast(float)i; }
real 	foo(real i)	{ return cast(float)i; }


Bar(foo);	// which foo, which return type?

as it stand the first foo encountered will be used (lexical order 
changes meaning in this case).
		



More information about the Digitalmars-d mailing list