[Issue 9493] std.algorithm.canFind returns true for empty string in array of integers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 10 03:34:22 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9493


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #1 from monarchdodra at gmail.com 2013-02-10 03:34:19 PST ---
(In reply to comment #0)
> It seems that std.algorithm.canFind returns true when checking for the empty
> string within an array of integers. This seems like unintended behaviour to me,
> so I'm reporting it as a bug. This bug is present on at least DMD 2.061.
> 
> Example:
> import std.algorithm;
> 
> void main()
> {
>     //This assertion should fail, but doesn't
>     assert(canFind([1, 2, 3, 4], ""));
> }

I think this is inteded behavior. You are basically looking for instances of
*nothing*, which, by definition, can be found inside everything (*). I'd expect
a true returned here, and this would be consistent with the rest of the finds
(AFAIK).

Are you getting a different behavior for, say arrays? eg "canFind([1, 2, 3],
(int[]).init)" I don't have access to my compiler, so that's an actual
question. If you *are* getting a different behavior, then I'd argue *that's* a
bug.

*: The only ambiguous case I see is if hasytack is empty, in which case I could
see it both ways, but I'd still lean for "true", since "empty is empty", so
"empty can be found inside empty".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list