[Issue 13124] New: std.algorithm.until with not-boolean predicates too

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jul 13 10:55:09 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13124

          Issue ID: 13124
           Summary: std.algorithm.until with not-boolean predicates too
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

This code:

void main() {
     import std.stdio, std.algorithm;
     auto s = "abcacaacba";
     s.filter!(c => c.among!('a', 'b')).writeln;
}

Outputs:

abaaaba



While this code:

void main() {
     import std.stdio, std.algorithm;
     auto s = "hello how\nare you";
     s.until!(c => c.among!('\n', '\r')).writeln;
}


Gives with dmd 2.066beta3:

...\dmd2\src\phobos\std\algorithm.d(5690,33): Error: cannot implicitly convert
expression (__lambda1(front(this._input))) of type uint to bool
test.d(4,7): Error: template instance test.main.until!((c) => c.among!('\x0a',
'\x0d'), string) error instantiating


So I suggest to improve std.algorithm.until, to allow that code.


Timon Gehr comments:


    private bool predSatisfied() // <-- don't say bool here
    {
        static if (is(Sentinel == void))
            return unaryFun!pred(_input.front); // or cast here
        else
            return startsWith!pred(_input, _sentinel); // and here
    }

--


More information about the Digitalmars-d-bugs mailing list