Bug 2871 – Take assumes that R.opIndex(uint) returns an lvalue.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-21T15:28:00Z
Last change time
2015-06-09T01:26:26Z
Assigned to
andrei
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2009-04-21T15:28:54Z
import std.range, std.algorithm; void main() { auto r = iota(0, 10, 1); assert(equal(r, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][])); r = iota(0, 11, 3); assert(equal(r, [0, 3, 6, 9][])); assert(r[2] == 6); } C:\dmd\windows\bin\..\..\src\phobos\std\range.d(1184): Error: this._input.opIndex(index) is not an lvalue C:\dmd\windows\bin\..\..\src\phobos\std\range.d(4): Error: template instance std.range.iota!(int,int,int) error instantiating This is caused by static if (isRandomAccessRange!(R)) ref ElementType!(R) opIndex(uint index) { enforce(_maxAvailable > index); return _input[index]; } in std.range. What is needed is some compile time reflection to determine whether a function returns by reference or value.
Comment #1 by 2korden — 2009-04-21T16:03:53Z
Can't auto help here? static if (isRandomAccessRange!(R)) auto opIndex(uint index) { enforce(_maxAvailable > index); return _input[index]; }
Comment #2 by dsimcha — 2010-06-17T18:51:56Z
This one's been fixed for ages. I don't know how it's slipped under the radar for so long.