Function Pointers with Type T
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 15 18:16:13 PDT 2014
You can get the code to compile with two changes:
bool function(T)(T val1,T val2) ptr=∁
should be:
bool function(T val1,T val2) ptr=&comp!T;
The function pointer itself isn't a template, so it doesn't need
the (T) parameter. Instead, since it is inside a template, you
can just use the T from the outside directly.
Moreover, comp has compile time arguments, so you can't take the
address of it without forwarding the arguments. So instead of
&comp, you use &comp!T - passing the T from the outside to the
comparison function too.
and also
int partition(T)(T[]list,bool function(T)(T val1,T val2)ptr,int
should be:
int partition(T)(T[]list,bool function(T val1,T val2)ptr,int
Again because the pointer isn't a new template, it should just
use the type T from the outer argument list.
More information about the Digitalmars-d-learn
mailing list