digitalmars.D.bugs - [Issue 21087] New: refRange() does not work with ranges which have
- d-bugmail puremagic.com (39/41) Jul 28 2020 https://issues.dlang.org/show_bug.cgi?id=21087
https://issues.dlang.org/show_bug.cgi?id=21087 Issue ID: 21087 Summary: refRange() does not work with ranges which have internal const fields Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: andrej.mitrovich gmail.com ``` import std.range; public static auto byRange () { static struct Range { size_t lbound = 0; const size_t hbound = 100; size_t length () const { return 0; } bool empty () const { return false; } int front () const { return 0; } void popFront () { } } return Range(0); } void main () { auto keys = byRange(); auto r = refRange(&keys); } ``` $ dmd test.d/Library/D/dmd/src/phobos/std/range/package.d(11504,13): Error: cannot modify struct instance `*this._range` of type `Range` because it contains `const` or `immutable` members /Library/D/dmd/src/phobos/std/range/package.d(12215,16): Error: template instance `std.range.RefRange!(Range)` error instantiatingtest.d(22,22): instantiated from here: `refRange!(Range)` As a workaround `hbound` can be declared an enum here. --
Jul 28 2020