[Issue 7839] New: std.range.count() too
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Apr 5 17:59:20 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7839
Summary: std.range.count() too
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-04-05 17:59:57 PDT ---
I'd like a count() in std.range. It's similar to the generator with the same
name in the Python itertools module:
http://docs.python.org/library/itertools.html#itertools.count
a count() is also useful with bigints, where you can't replace it with
iota(BigInt.max).
A bare-bones implementation that shows it basic semantics (but it's useful to
add few more methods):
struct Count(T) {
T n;
this(T n_) { this.n = n_; }
const bool empty = false;
@property T front() { return n; }
void popFront() { /* n++; */ n += 1; }
}
// Two helper functions
Count!T count(T)(T start) { return Count!T(start); }
Count!T count(T)() { return Count!T(cast(T)0); }
--
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