www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9493] New: std.algorithm.canFind returns true for empty string in array of integers

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9493

           Summary: std.algorithm.canFind returns true for empty string in
                    array of integers
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: monkeyworks12 hotmail.com


--- Comment #0 from monkeyworks12 hotmail.com 2013-02-09 23:58:48 PST ---
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], ""));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9493


monarchdodra gmail.com changed:

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


--- Comment #1 from monarchdodra 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: -------
Feb 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9493


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com


--- Comment #2 from Jonathan M Davis <jmdavisProg gmx.com> 2013-02-10 03:46:42
PST ---
I think that there's a good chance that it's intended behavior that looking for
an empty range with canFind always returns true. However, the fact that canFind
is accepting a _string_ as the needle when the haystack is int[] seems very
wrong.

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