Function Pointers with Type T

amparacha via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 16 10:32:01 PDT 2014


Thanks Adam you saved me from alot.Just one more question how can
I compare two arguments of type T.
On Tuesday, 16 September 2014 at 01:16:14 UTC, Adam D. Ruppe
wrote:
> 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