Templates and Functions
    Oliver 
    ruebenko at imtek.de
       
    Wed Sep 12 03:07:18 PDT 2007
    
    
  
Hi,
I'd like to hand over a function to a template. However I am unable to get access to the functions argument type. In the following code the function's argument has been set to double but it should actually be of type T2. T2 is this case is an array and i would like something to give me the type of the array which i can then use to replace the double with. 
Any suggestions on how to do this? Thanks a lot.
-------
import std.stdio;
import std.math;
T1 [] dMap( T1, T2 )( T1 function(double) fp, T2 array) {
        T1 newArray[];
        newArray.length = array.length;
        for(int i = 0; i < array.length; i++) {
            newArray[i] = fp(array[i]);
        };
        return newArray;
}
void main() {
        auto b = [0., 6.5, 3.1415];
        real function(double a) fp; 
        fp = function(double a) { return sin(a);} ;
        auto d = dMap(fp,b);
        writefln("d = ", d);
}
    
    
More information about the Digitalmars-d-learn
mailing list