On page 143 there's a new find() overloaded function which is more specialized than the last generic function, but I'm still getting an ambiguity error. Although the book doesn't state if that specific unittest should work, so I'm left wondering :) Here's the code:<br>
<br>void main()<br>{<br>}<br><br>T1[] find(T1, T2)(T1[] longer, T2[] shorter)<br> if (is(typeof(longer[0 .. 1] == shorter) : bool))<br>{<br> while (longer.length >= shorter.length) {<br> if (longer[0 .. shorter.length] == shorter)<br>
break;<br> longer = longer[1 .. $];<br> }<br> return longer;<br>}<br><br>int[] find(int[] longer, int[] shorter) { }<br><br>unittest {<br> int[] ints1 = [1, 2, 3, 5, 2] ;<br> int[] ints2 = [3, 5];<br>
auto test = find(ints1, ints2);<br>}<br><br>test.d(16): Error: function test.find conflicts with template test.find(T1,T2) if (is(typeof(longer[0..1] == shorter) : bool)) at test.d(5)<br><br><br>And on page 145 the last example is:<br>
<br>void main() { }<br><br>void transmogrify(uint) { }<br>void transmogrify(long) { }<br>void transmogrify(T)(T value) { }<br><br>unittest {<br> transmogrify(42);<br> transmogrify("hello");<br> transmogrify(1.1);<br>
}<br><br>test2.d(5): Error: template test2.transmogrify(T) conflicts with function test2.transmogrify at test2.d(3)<br><br><div class="gmail_quote">On Wed, Jul 28, 2010 at 7:32 PM, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com">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;">Woops, I got confused. I was thinking about structs, not arrays. <br><br>But yeah, in this case a float gets compared to a double and it seems to evaluate to false.<div>
<div></div><div class="h5"><br><br><div class="gmail_quote">On Wed, Jul 28, 2010 at 7:26 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisprog@gmail.com" target="_blank">jmdavisprog@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;"><div>On Wednesday, July 28, 2010 09:49:52 Andrej Mitrovic wrote:<br>
> IIRC arrays are value types and as such they are compared bit-by-bit<br>
> to each other, right?<br>
<br>
</div>Dynamic arrays are reference types (though static arrays are indeed value<br>
types), and they evaluate for equality by comparing each element in turn (though<br>
presumably, they compare their length first and don't bother with element<br>
comparisons if the lengths don't match). Look at section 4.1.5 on page 100 of<br>
TDPL.<br>
<font color="#888888"><br>
- Jonathan M Davis<br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>