Problem with templates

Sean Reque seanthenewt at yahoo.com
Mon Jul 7 08:13:33 PDT 2008


Could someone help me understand why this function doesn't work?

R delegate(T) my_compose(R, IR, IT, T...)(IR delegate(T) first, R delegate(IT) second) {
  return delegate(T args) { second(first(args)); };
}

I attempt to invoke the function like this:

  my_compose(&SQLAllocHandle, &SQL)(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);

where SQLAllocHandle is a C function that returns a short and SQL is a function that accepts a short as its only parameter. I get the following error:

test.d(35): template test.my_compose(R,IR,IT,T...) does not match any function template declaration
test.d(35): template test.my_compose(R,IR,IT,T...) cannot deduce template function from argument types !()(shortC  function(short, void*, void**),void function(short rc))
test.d(35): Error: function expected before (), not (my_compose(R,IR,IT,T...))((& SQLAllocHandle),(& SQL)) of type int


I am using two separate template types, IR and IT, because according to the error message function 1 returns a shortC and function two accepts a short. I assume a shortC is implicitly convertible to a short :). I am guessing the shortC comes from the fact that SQLAllocHandle is an extern(C) function. 

I tried to model this function off of the Curry example in d 2.0 on this page: http://digitalmars.com/d/2.0/template.html. I am using version 2.015. I really don't understand how what I am doing is any different conceptually than this curry example, which works fine.




More information about the Digitalmars-d-learn mailing list