Regarding isSorted

Jonathan M Davis jmdavisProg at gmx.com
Tue Feb 5 17:29:17 PST 2013


On Wednesday, February 06, 2013 01:33:29 bearophile wrote:
> This used to print true-false, now prints true-true. Is this a
> bug?
> 
> 
> import std.stdio, std.algorithm;
> void main() {
>      auto x = "abcd";
>      writeln(isSorted(x));
>      auto y = "acbd";
>      writeln(isSorted(y));
> }
> 
> 
> Maybe this line:
> 
> https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d
> #L9237
> 
>          for (; !ahead.empty; ahead.popFront(), ++i)
> 
> Should be:
> 
>          for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i)

That definitely looks like a bug. "acbd" _isn't_ sorted.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list