Bug 13124 – std.algorithm.until with not-boolean predicates too

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-07-13T17:55:00Z
Last change time
2015-02-18T03:41:04Z
Keywords
rejects-valid
Assigned to
peter.alexander.au
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-13T17:55:09Z
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 }
Comment #1 by peter.alexander.au — 2015-01-02T21:36:07Z
Comment #2 by github-bugzilla — 2015-01-11T05:01:34Z
Comment #3 by github-bugzilla — 2015-02-18T03:41:04Z