D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2983 - Elaborate restricted variadic function does not compile
Summary: Elaborate restricted variadic function does not compile
Status: RESOLVED DUPLICATE of issue 3379
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-15 13:49 UTC by Andrei Alexandrescu
Modified: 2015-06-09 05:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-05-15 13:49:30 UTC
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 Don 2009-10-14 00:09:03 UTC
This is failing because 'a' isn't available while in the constraint.
Comment 2 Andrei Alexandrescu 2009-10-14 07:01:38 UTC
(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 Don 2009-10-16 18:45:01 UTC
This is fixed by match to bug 3379.

*** This issue has been marked as a duplicate of issue 3379 ***