<br><br><div class="gmail_quote">On Sun, Aug 1, 2010 at 11:15 PM, Philippe Sigaud <span dir="ltr"><<a href="mailto:philippe.sigaud@gmail.com">philippe.sigaud@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="im">On Sat, Jul 31, 2010 at 17:24, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I think there really is some bug here. I tried to use your template helper function, and it seems the order in which I put two constraints in a template signature changes the way dmd compiles the code. Consider this:<div>
</div></blockquote><div> </div></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>T[] find(T, E)(T[] haystack, E needle)</div><div class="im">
if (is(typeof(haystack[0] != needle) == bool) &&<br> areComparable!(T, E))<div><br></div></div></blockquote><div>...</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>T1[] find(T1, T2)(T1[] longer, T2[] shorter)<br></div> if (is(typeof(longer[0 .. 1] == shorter) : bool) && (areComparable!(T1, T2)))<div></div></blockquote><div><br></div><div> </div>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>This will give out the error "incompatible types for comparing of string and immutable(char)". </div>
</blockquote><div><br></div><div>That's because the first part of the constraint is tested, to allow for short-circuiting the second part. So the bad array comparison triggers the problem in object._EqArray.</div><div>
<br></div><div>You should always test for the most general constraint first, I guess. In this particular case, use areComparable!(A,B) as the first argument to && in both templates.</div><br></div></blockquote><div>
</div></div>Let me see if I'm getting this right. <br><br>false && true will short circuit to false (this is normal).<br><br>true && false will short circuit to true? How can that be? It's not a logical OR, its an AND, and as far as I know both expressions need to be True to evaluate to True. Or is it different for template constraints?<br>
<br>Thanks again for the std.math.approxEqual and binaryFun tips.<br>