Thread overview
[Issue 2871] New: Take assumes that R.opIndex(uint) returns an lvalue.
Apr 21, 2009
d-bugmail
Apr 21, 2009
d-bugmail
Jun 18, 2010
David Simcha
April 21, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2871

           Summary: Take assumes that R.opIndex(uint) returns an lvalue.
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: dsimcha@yahoo.com


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.


-- 

April 21, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2871





------- Comment #1 from 2korden@gmail.com  2009-04-21 16:03 -------
Can't auto help here?

    static if (isRandomAccessRange!(R))
        auto opIndex(uint index)
        {
            enforce(_maxAvailable > index);
            return _input[index];
        }


-- 

October 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2871


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2871


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from David Simcha <dsimcha@yahoo.com> 2010-06-17 18:51:56 PDT ---
This one's been fixed for ages.  I don't know how it's slipped under the radar for so long.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------