Bug 24152 – range .until evaluates .front twice

Status
NEW
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2023-09-20T01:32:30Z
Last change time
2024-12-01T16:41:49Z
Assigned to
No Owner
Creator
Jan Jurzitza
Moved to GitHub: phobos#9864 →

Comments

Comment #0 by d.bugs — 2023-09-20T01:32:30Z
``` import std.algorithm : map, until; import std.range : iota; import std.array : array; int access; int logAccess(int x) { access++; return x; } void main() { iota(10).map!logAccess.until(10).array; assert(access == 20); } ``` if you remove the `.until(10)`, you get `access == 10`
Comment #1 by d.bugs — 2023-09-20T01:46:17Z
`std.algorithm:cache` could be used, but that still evalutes .front one time too many compared to when `until` should stop when No.openRight is passed in as argument, e.g. ``` iota(10).map!logAccess.cache.until(5, No.openRight).array; ``` will call logAccess on 0, 1, 2, 3, 4, 5 and 6
Comment #2 by robert.schadek — 2024-12-01T16:41:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9864 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB