Bug 1049 – Template specialization via delegate parameters

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-03-10T08:30:00Z
Last change time
2014-02-16T15:23:51Z
Assigned to
bugzilla
Creator
gavrilyak

Comments

Comment #0 by gavrilyak — 2007-03-10T08:30:53Z
If template function has delegate argument the type of this argument is not used when deducting the right function to use. Compiler gives error about conflicting templates At the same time compiler refuses to accept one such template instead of another, so it looks like 2 different templates to it. Example T[] filter (T) (T[] me, bool delegate (T) predicate) { T[] result; foreach (it; me) if (predicate(it)) result ~= it; return result; } T[] filter (T) (T[] me, bool delegate (T,int) predicate) { T[] result; foreach (i, it; me) if (predicate(it, i)) result ~= it; return result; } void main(){ int[] arr = [1,2,3,4]; auto gt2 = filter(arr, (int it){return it>3;}); auto first2 = filter(arr, (int it,int i){return i<2;}); } This code produces compiler error >>template tdel.filter(T) conflicts with tdel.filter(T) at tdel.d(1) Changing first filter to _filter give another error tdel.d(19): template tdel.filter(T) does not match any template declaration tdel.d(19): template tdel.filter(T) cannot deduce template function from argument types (int[],bool delegate(int it)) So it seems compiler knows that functions are different and cannot use one instead of another, so there is no conflict here.
Comment #1 by gavrilyak — 2007-03-14T14:43:20Z
Issue is invalid, that is how templates type resolution currently work. Maybe this needs to be feature request, but not a bug.