[Issue 21087] New: refRange() does not work with ranges which have internal const fields
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 29 05:10:59 UTC 2020
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 at puremagic.com
Reporter: andrej.mitrovich at 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 instantiating
test.d(22,22): instantiated from here: `refRange!(Range)`
As a workaround `hbound` can be declared an enum here.
--
More information about the Digitalmars-d-bugs
mailing list