www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6490] New: countUntil will take a non-range for its second argument

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

           Summary: countUntil will take a non-range for its second
                    argument
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
This code compiles:

import std.algorithm;

void main()
{
    string str = "abc123";

    auto i = countUntil!((a, b){return (a >= '0' && a <= '9') || a == '.';})
                         (str, 0);
}

It shouldn't. Notice that the second argument to countUntil is 0, which is an
int, not a range.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 14 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6490


klickverbot <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code klickverbot.at



---
Are you sure that this is a bug? The documentation says that it counts until
haystack.startsWith!pred(needle) is true, and startsWith is also defined for
single element needles. You are right, the usefulness of this behavior is
questionable, though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6490


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



PDT ---
Okay. I misunderstood countUntil. Its signature is

sizediff_t countUntil(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
if (is(typeof(startsWith!pred(haystack, needle))))

Of course, I didn't see the template constraint in the documentation, and given
the type names, I assumed that needle had to be a range. My mistake. There's no
problem with this code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 14 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6490




PDT ---
The real issue here IMHO is the fact that 0 implicitly converts to a dchar, but
that's not going to change anytime soon. The original code that I copied this
from was doing that though. I wouldn't normally put a 0 there.

In any case, this isn't a bug.

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