www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug in std.range.retro?

reply Sam Hu <samhudotsamhu gmail.com> writes:
Originally I posted in learn:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=16913

Move here to double confirm whether it is a bug:
static if (isRandomAccessRange!(R) && hasLength!(R))
        ref ElementType!(R) opIndex(uint n)
        {
            return _input[_input.length - n + 1];
        }

Shouldn't it be _input.length-(n+1) ?

Regards,
Sam
Jun 22 2009
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Sam Hu wrote:
 Originally I posted in learn:
 
 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=16913
 
 Move here to double confirm whether it is a bug:
 static if (isRandomAccessRange!(R) && hasLength!(R))
         ref ElementType!(R) opIndex(uint n)
         {
             return _input[_input.length - n + 1];
         }
 
 Shouldn't it be _input.length-(n+1) ?
 
 Regards,
 Sam
Well r[0] would translate to r.opIndex(0) which means it will return r._input[r._input.length - 0 + 1] = r._input[r._input.length + 1] which is outside the array bounds. So yes, it's a bug.
Jun 22 2009