TDPL: Overloading template functions
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Jul 28 09:49:52 PDT 2010
It was adequate for the first function, but I never knew why you've changed
"== bool" to ": bool", and why you're using slices in the second templated
function. Philippe explained it in more detail so I'm starting to get it.
Otherwise, the only issue left is the float vs double comparisons.
For this unittest:
double[] d1 = [6.0, 1.5, 2.4, 3];
float[] d2 = [1.5, 2.4];
assert(find(d1, d2) == d1[1 .. $]);
Inside the second template function I've added a writeln, and I can see the
if statement evaluates "[1.5, 2.4] == [1.5, 2.4]" to false and will not
break out of the loop. I don't know whether this is a DMD bug or if "float[]
d2" should be changed to "double[] d2" in TDPL, since that runs fine. IIRC
arrays are value types and as such they are compared bit-by-bit to each
other, right? And since doubles and floats have different sizes, that
unittest then fails.
On Wed, Jul 28, 2010 at 6:19 PM, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:
> Andrej Mitrovic wrote:
>
>> Also, Andrei, you never explained the if(is()) signature of the second
>> templated function. I hope to get some pointers on that. :)
>>
>
> Is the explanation on page 141 adequate?
>
> Andrei
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100728/47cc4f4c/attachment.html>
More information about the Digitalmars-d
mailing list