Problem with templates

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Jul 7 09:35:55 PDT 2008


"Sean Reque" <seanthenewt at yahoo.com> wrote in message 
news:g4tg3j$2pta$1 at digitalmars.com...

> I tried writing the compose function to return a static function. Here is 
> the new function:
>
> ReturnType!(f2) my_compose2(alias f1, alias f2)(ParameterTypeTuple!(f1) 
> args) {
>   return second(first(args));
> }
>
> I again try to compose the functions and invoke them, this time like so:
>
>  my_compose2!(&SQLAllocHandle, &SQL)(SQL_HANDLE_ENV, SQL_NULL_HANDLE, 
> &env);
>
> Again, I get this error message:
>
> test.d(41): template test.my_compose2(alias f1,alias f2) does not match 
> any function template declaration
> test.d(41): template test.my_compose2(alias f1,alias f2) cannot deduce 
> template function from argument types !(& SQLAllocHandle,& 
> SQL)(const(short),const(void*),void**)

One, you're still using "first" and "second" but you've changed the names to 
"f1" and "f2".

Two, you don't use address-of when passing alias arguments to templates. 
Just use "my_compose2!(SQLAllocHandler, SQL)".

>
> I still am not sure why my original compose function didn't work, either. 
> Someone else posted that I should try using function inputs, but I thought 
> that D could implicitly convert function pointers to delegates.

It can't.  Delegates and functions currently have different calling 
conventions and the compiler cannot automatically convert one to the other. 
Was this just intuition or did you read that it would somewhere?

> Perhaps I am doing something else wrong, or making an incorrect 
> assumption? Also, creating a static function that returns a value isn't 
> sufficient for what I need. Basically I want to be able to create D 
> versions of every C ODBC call I need that will check the return values of 
> these functions and throw an exception on error. I could do that manually 
> for each function, but then I might as well be coding in C or C++ :).

Why can't this be done with a static function?  Or rather, I'm not seeing 
how using a delegate makes what you want to do easier. 




More information about the Digitalmars-d-learn mailing list