Error using `equal` with various string types
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Feb 24 09:53:16 PST 2013
On 2/24/13, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> Those _do_ work. The problem is that you're not trying that; you're trying
> ["foo"].equal(["foo"d]);
Ah that makes sense, thanks.
A run of the mill implementation takes care of things:
bool equal(Range1, Range2)(Range1 r1, Range2 r2)
if (isInputRange!Range1 && isInputRange!Range2
&& isInputRange!(ElementType!Range1)
&& isInputRange!(ElementType!Range2))
{
if (r1.length != r2.length) return false;
foreach (lhs, rhs; zip(r1, r2))
{
if (!.equal(lhs, rhs))
return false;
}
return true;
}
It's not tested though, but I see what you mean by recursion now. I'll
file an enhancement.
One thing I don't understand is why the above won't work if I put it
in my own module (compile-time error), it has to be put in
std.algorithm for all the template overloads to be part of one
overload set. Using aliases won't work either, e.g.:
import std.algorithm;
alias std.algorithm.equal equal; // conflict
bool equal(Range1, Range2)(Range1 r1, Range2 r2)
if (isInputRange!Range1 && isInputRange!Range2
&& isInputRange!(ElementType!Range1)
&& isInputRange!(ElementType!Range2))
{
if (r1.length != r2.length) return false;
foreach (lhs, rhs; zip(r1, r2))
{
if (!.equal(lhs, rhs))
return false;
}
return true;
}
It sounds to me like it's a compiler bug.
More information about the Digitalmars-d-learn
mailing list