Bug 8278 – std.range.chunks for generic Forward Ranges?
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-21T12:21:00Z
Last change time
2014-07-17T18:43:02Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-06-21T12:21:33Z
From the online docs of std.range.chunks:
This range iterates over fixed-sized chunks of size chunkSize of a source range. Source must be an input range with slicing and length.
Is it possible to modify chunks() to allow it to also work on forward ranges that have no slicing and lenght?
An example is chunking the output of recurrence():
auto r = recurrence!q{(22695477 * a[n-1] + 12345) % 1073741824}(123456789U);
auto c = std.range.chunks(r, 5);
Comment #1 by hsteoh — 2014-07-17T18:43:02Z
Works in git HEAD:
-----
import std.range, std.algorithm;
void main() {
struct FwdRange { // N.B. no slicing or length here
enum empty = false;
auto front = 1;
void popFront() {}
@property auto save() { return this; }
}
auto c = std.range.chunks(FwdRange(), 5);
import std.stdio;
writeln(c.take(10));
}
-----