Templated Function pointers

js.mdnq js_adddot+mdng at gmail.com
Thu Nov 29 15:17:07 PST 2012



I need to store a templated function in a function pointer, how 
can I do this?


e.g.,

void function(double) myfuncptr;
void myfunc(double d) { }
myfuncptr = myfunc;

Now I would like to use a template parameter instead of double.

In C++ one can do this by using boosts binding's and function 
types.

For example, I want something like this

void function(F)(F) funcptr;

void Bind(T)(void function(T)(T) v)
{
     funcptr = v; // F is sort of deduced automatically as being 
T. Obviously problematic but effectively what I want to do.
}

This way I can bind to any function that takes a single type 
parameter and returns a void.


void function(F) myfuncptr;  // F is undefined
void myfunc(T)(T d) { }      //
myfuncptr = myfunc;

To do this using boost I would simply bind the parameter so 
myfuncptr would not depend on an arbitrary type.

I need a rather performant way to do this too.





More information about the Digitalmars-d-learn mailing list