Bug 2983 – Elaborate restricted variadic function does not compile
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-05-15T13:49:00Z
Last change time
2015-06-09T05:15:06Z
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2009-05-15T13:49:30Z
I suspect there are multiple reasons for which the code below does not compile. It should, however, compile and run properly:
auto max(T...)(T a)
if (T.length == 2
&& is(typeof(a[1] > a[0] ? a[1] : a[0]))
|| T.length > 2
&& is(typeof(max(max(a[0], a[1]), a[2 .. $])))) {
static if (T.length == 2) {
return a[1] > a[0] ? a[1] : a[0];
} else {
return max(max(a[0], a[1]), a[2 .. $]);
}
}
void main() {
assert(max(4, 5) == 5);
assert(max(3, 4, 5) == 5);
}
Comment #1 by clugdbug — 2009-10-14T00:09:03Z
This is failing because 'a' isn't available while in the constraint.
Comment #2 by andrei — 2009-10-14T07:01:38Z
(In reply to comment #1)
> This is failing because 'a' isn't available while in the constraint.
Exactly. The idea is that making the parameter names available would simplify writing template constraints a lot.
Comment #3 by clugdbug — 2009-10-16T18:45:01Z
This is fixed by match to bug 3379.
*** This issue has been marked as a duplicate of issue 3379 ***