[Issue 15162] New: byDchar calls empty twice in a row
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Oct 5 13:11:07 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15162
Issue ID: 15162
Summary: byDchar calls empty twice in a row
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
The following program:
import std.utf;
import core.stdc.stdio;
struct S {
bool empty() { printf("empty\n"); return !s.length; }
@property char front() { printf("front\n"); return s[0]; }
void popFront() { printf("popFront()\n"); s = s[1 .. $]; }
string s;
}
void main() {
auto s = S("hello");
auto r = s.byDchar();
r.empty;
r.front;
r.popFront();
r.empty;
r.front;
r.popFront();
}
prints 'empty' twice:
empty
empty
front
popFront()
empty
empty
front
popFront()
For efficiency, it should only call empty once per character.
--
More information about the Digitalmars-d-bugs
mailing list