Skip to content

Commit ec2c846

Browse files
committed
Replaced foreach loop in std.algorithm.equal with a for loop that calls popFront on both ranges. This ensures that code points are not compared with code units in conjunction with narrow strings.
1 parent 9ffdaa9 commit ec2c846

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

std/algorithm.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,11 +4321,10 @@ bool equal(alias pred = "a == b", Range1, Range2)(Range1 r1, Range2 r2)
43214321
if (isInputRange!(Range1) && isInputRange!(Range2)
43224322
&& is(typeof(binaryFun!pred(r1.front, r2.front))))
43234323
{
4324-
foreach (e1; r1)
4324+
for (; !r1.empty; r1.popFront(), r2.popFront())
43254325
{
43264326
if (r2.empty) return false;
4327-
if (!binaryFun!(pred)(e1, r2.front)) return false;
4328-
r2.popFront;
4327+
if (!binaryFun!(pred)(r1.front, r2.front)) return false;
43294328
}
43304329
return r2.empty;
43314330
}
@@ -4345,6 +4344,9 @@ unittest
43454344
// predicated
43464345
double[] c = [ 1.005, 2, 4, 3];
43474346
assert(equal!(approxEqual)(b, c));
4347+
4348+
// utf-8 strings
4349+
assert(equal("æøå", "æøå"));
43484350
}
43494351

43504352
// cmp

0 commit comments

Comments
 (0)