Function Pointers with Type T

Phil Lavoie via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 15 09:40:12 PDT 2014


On Monday, 15 September 2014 at 16:28:19 UTC, amparacha wrote:
> Can anyone looks at the following code to fix it.I am having 
> error when using pointers to functions with argument of type 
> T.This is a small portion of a program doing a generic quick 
> sort by passing a comparison function as an argument.
>
> import std.stdio;
>
>
> int main(){
>
> return 0;
> }
>
> bool comp(T)(T left,T right){
> //some comparison criteria
> return false;
> }
>
>
> void sort(T)(T[]list,int left,int right)
> {
> int spiltPoint;
> bool function(T)(T val1,T val2) ptr=∁
> spiltPoint=partition(list,ptr,left,right);	
> }
>
> int partition(T)(T[]list,bool function(T)(T val1,T val2)ptr,int 
> left,int right){
>
> return 2;
>
> }

At first glance it looks like you have a syntax error:
bool function(T)(T val1, T val2) ptr ...
should be:
auto ptr = &(comp!(T)); //Instantiate the template function 
first. Auto deduces the type.



More information about the Digitalmars-d mailing list