[Issue 10087] New: std.range.chunks problem with chunkSize = 0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 15 09:49:45 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10087

           Summary: std.range.chunks problem with chunkSize = 0
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-05-15 09:49:44 PDT ---
import std.stdio: writeln;
import std.range: chunks;
void main() {
    chunks("abcd"d, 0).writeln;
}

Prints an unbound range of empty strings, I think this is not good:

["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ...

I suggest to refuse the chunkSize = 0 with a pre-condition (or worse with an
enforce).

An alternative solution is to make 0 a special case, and return the whole
iterable:

std.range.chunks("abcd"d, 0).writeln;

==>

["abcd"]

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


More information about the Digitalmars-d-bugs mailing list