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? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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
|
Copyright © 1999-2021 by the D Language Foundation