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



--- Comment #3 from Don <clugd...@yahoo.com.au> 2009-10-16 18:44:16 PDT ---
Since the patch contains two nearly-identical parts they probably should be
factored out into a function. But it works.

Test cases for the patch:
------
/ bug3379
T1[] find(T1, T2)(T1[] longer, T2[] shorter)
   if (is(typeof(longer[0 .. 1] == shorter) ))
{
   while (longer.length >= shorter.length) {
      if (longer[0 .. shorter.length] == shorter) break;
      longer = longer[1 .. $];
   }
   return longer;
}

// bug2983
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);
   double[] d1 = [ 6.0, 1.5, 2.4, 3 ];
   double[] d2 = [ 1.5, 2.4 ];
   assert(find(d1, d2) == d1[1 .. $]);
}

void bad(T)(T x) if (is(T : idouble)) {   }
static assert(!is(typeof(bad(17))));   // must be rejected
static assert(!is(typeof(bad!(int)(2)))); // reject even if types specified
static assert(is(typeof(bad(3.0i))));

void fun(T)(char a, T[] b...) if (is(typeof(b[0]>b[1]))) {}
static assert(is(typeof(fun('x', 3.0, 4.0, 5.0))));

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

Reply via email to