Bug 15264 – opDispatch cannot implement range primitives

Status
NEW
Severity
enhancement
Priority
P4
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-10-30T01:38:28Z
Last change time
2024-12-07T13:35:54Z
Assigned to
No Owner
Creator
ryan
Moved to GitHub: dmd#17315 →

Comments

Comment #0 by ryan — 2015-10-30T01:38:28Z
If you use opDispatch to implement range primitives, isInputRange passes yet it cannot be used in foreach loops: --- import std.range; struct R { auto vals = iota(0, 5); auto opDispatch(string s)() { return mixin("vals."~s); } // uncomment to pass: //auto front() { return vals.front; } //auto popFront() { return vals.popFront; } //auto empty() { return vals.empty; } } // R is an input range, but cannot be used in foreach: static assert(isInputRange!R); // pass static assert(__traits(compiles, { foreach(v ; R()) { } })); // fail --- We either need to allow foreach via opDispatched range primitives or have is*Range return false in this case. Personally, I would like to see foreach work in this case, though there may be concerns over 'accidental' range implementation: http://forum.dlang.org/thread/[email protected]
Comment #1 by robert.schadek — 2024-12-07T13:35:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17315 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB