Skip to content

Commit

Permalink
Merge pull request #1744 from 9rnsr/fix11603
Browse files Browse the repository at this point in the history
Issue 11603 - std.algorithm.canFind does not work when needle is 1-byte zero
  • Loading branch information
monarchdodra committed Dec 4, 2013
2 parents 04c43ce + ab34fb9 commit c98f5f5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion std/algorithm.d
Expand Up @@ -3916,7 +3916,7 @@ if (isInputRange!InputRange &&
{
EType* ptr = null;
//Note: we use "min/max" to handle sign mismatch.
if (min(EType.min, needle) == EType.min, needle && max(EType.max, needle) == EType.max)
if (min(EType.min, needle) == EType.min && max(EType.max, needle) == EType.max)
ptr = cast(EType*) memchr(haystack.ptr, needle, haystack.length);

return ptr ?
Expand Down Expand Up @@ -4042,6 +4042,15 @@ unittest
dg();
assertCTFEable!dg;
}
unittest
{
// Bugzilla 11603
enum Foo : ubyte { A }
assert([Foo.A].find(Foo.A).empty == false);

ubyte x = 0;
assert([x].find(x).empty == false);
}

/**
Finds a forward range in another. Elements are compared for
Expand Down

0 comments on commit c98f5f5

Please sign in to comment.