Problem with templates

Sean Reque seanthenewt at yahoo.com
Mon Jul 7 10:35:53 PDT 2008


BCS Wrote:

> Reply to Sean,
> 
> >> 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?
> >> 
> > Take this example:
> > 
> 
> [...]
> 
> > void main()
> > {
> > int plus(int x, int y, int z)
> > {
> > return x + y + z;
> > }
> > auto plus_two = Curry(&plus, 2);
> > 
> > Notice how the function Curry accepts a delegate, but a function
> > pointer is actually passed in. I have personally re-written this
> > function to take advantage of D2 closures and it worked perfectly
> > fine.
> > 
> 
> taking the address of a (non static) nested functions generates a delegate, 
> not a function pointer.
> 
> 

I see. Any idea why this revised function still doesn't work?

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

test.d(40): template test.my_compose(R,IR,IT,T...) does not match any function template declaration
test.d(40): 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(40): Error: function expected before (), not (my_compose(R,IR,IT,T...))((& SQLAllocHandle),(& SQL)) of type int



More information about the Digitalmars-d-learn mailing list