[Issue 2983] New: Elaborate restricted variadic function does not compile

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 15 13:49:31 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2983

           Summary: Elaborate restricted variadic function does not
                    compile
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list