[Issue 5550] std.range.enumerate()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 26 17:19:51 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5550
--- Comment #2 from bearophile_hugs at eml.cc 2012-03-26 17:20:14 PDT ---
The problem was caused by the alias this. This avoids the problem:
import std.stdio, std.algorithm, std.range, std.typecons, std.traits,
std.array;
struct Enumerate(R) {
R r;
int i;
@property bool empty() {
return this.r.empty;
}
@property Tuple!(typeof(this.i), typeof(R.init.front)) front() {
return typeof(return)(i, this.r.front);
}
void popFront() {
this.r.popFront();
this.i++;
}
}
Enumerate!R enumerate(R)(R range, int start=0) if (isInputRange!R) {
return Enumerate!R(range, start);
}
void main() {
auto flags = [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1];
flags.enumerate(2).filter!q{!a[1]}().map!q{a[0]}().writeln();
}
The last line is noisy but it's readable.
This is less noisy but longer:
flags.enumerate(2).filter!(t => !t[1])().map!(t => t[0])().writeln();
--
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