<div class="gmail_quote">On Wed, Jul 28, 2010 at 05:50, Andrej Mitrovic <span dir="ltr">&lt;<a href="mailto:andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>&gt;</span> wrote:<br><div><br></div><div>I won&#39;t comment on the double/float issue, I do not anything about it.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">T[] find(T, E)(T[] haystack, E needle)<br>
    if (is(typeof(haystack[0] != needle) == bool))<br><br>
T1[] find(T1, T2)(T1[] longer, T2[] shorter)<br>
    if (is(typeof(longer[0 .. 1] == shorter) : bool))<br><br>
Also, Andrei, you never explained the if(is()) signature of the second templated function. I hope to get some pointers on that. :)<br>
</blockquote></div><div><br></div>I&#39;ll have a try at this one.<div>As you may know, the is(typeof()) syntax is a way to try to compile an expression and see if it works. If it works, it has a type, given by typeof and is(Type) returns true. So the first one is really saying: &quot;Hey compiler, may I compare an element of haystack (of type T) with an E</div>
<div>In this case, longer is an array. So longer[0] would be an element, a T1. There is no chance that shorter will match as an element cannot be equal to an array ... except, of course, if longer is an array of T2[]  (T1 == T2[]). Longer is a T2[][]. That may happen for arrays of strings, strings being arrays of chars. And I think that&#39;s the problem you have in your last unit test.<div>
<br></div><div>Anyway, he takes longer[0..1] to get a slice, which is a dynamic array, a T1[] and hence comparable to a T2[]... most of the time.</div><div><br></div><div>As for using &#39;: bool&#39; instead of &#39;== bool&#39; as in the first find(),  I don&#39;t think there is any difference in this case. I understand T == U as &#39;T is the exact same type as U&#39;, whereas T : U is for me &quot;T is a subtype of U&quot;. But then, a subtype of bool is pretty much constrained to be a bool. The T : U syntax is pretty much only used for classes : if(is(T : MyClass)) is saying : &#39;compile this only if T is a subclass of MyClass&#39;.</div>
<div><br></div><div><br></div><div>Philippe</div><div><br></div><div><br></div><div><br></div><div>, except if longer is in fact</div></div>