View mode: basic / threaded / horizontal-split · Log in · Help
May 25, 2012
Why doesn't this throw?
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
Re: Why doesn't this throw?
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
Top | Discussion index | About this forum | D home