Bug 3531 – 'curry' doesn't work for templated functions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-11-20T03:56:00Z
Last change time
2015-06-09T01:27:05Z
Assigned to
andrei
Creator
samukha
Comments
Comment #0 by samukha — 2009-11-20T03:56:04Z
auto add(A, B)(A x, B y)
{
return x + y;
}
void main()
{
alias curry!(add, 5) add5;
assert(add5(6) == 11);
}
test.d(57): Error: template std.functional.curry!(add,5).curry(T) if (is(typeof(fun(arg,T.init)))) does not match any fu
nction template declaration
test.d(57): Error: template std.functional.curry!(add,5).curry(T) if (is(typeof(fun(arg,T.init)))) cannot deduce templat
e function from argument types !()(int)
The problem is with the constraint for curry(T)(T arg2). Remove the constraint to workaround.
Comment #1 by bugzilla — 2009-11-20T06:29:58Z
The is(typeof(...)) constraint can be replaced with __traits(compiles, ...). This works:
auto curry(T)(T arg2) if (__traits(compiles, { fun(arg, T.init); }))
{
return fun(arg, arg2);
}
Comment #2 by samukha — 2009-11-20T08:17:09Z
Just want to note that it is not __traits(compiles) that makes the example work, but the function being wrapped in the delegate literal. This works as well:
auto curry(T)(T arg2) if (is(typeof( { fun(arg, T.init); } )))