www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why doesn't this throw?

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
import std.algorithm;
import std.stdio;

void main()
{
    int[] a = [1, 2, 3];
    a = a.remove(3);
    writeln(a);
}

writes [1, 2]

If I'd called a.remove with index 2 I would get the above result, but
index 3 is clearly out of bounds, so why'd it remove the last element
instead of throwing?
May 25 2012
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 25 May 2012 08:59:47 -0400, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 import std.algorithm;
 import std.stdio;

 void main()
 {
     int[] a = [1, 2, 3];
     a = a.remove(3);
     writeln(a);
 }

 writes [1, 2]

 If I'd called a.remove with index 2 I would get the above result, but
 index 3 is clearly out of bounds, so why'd it remove the last element
 instead of throwing?

Because remove has a bug. -Steve
May 25 2012