Re: Do you have a better way to remove element from a array?

2015-02-05 Thread Tobias Pankrath via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:25:37 UTC, FrankLike wrote: Now I can remove element from a array: module removeOne; import std.stdio; import std.array; import std.algorithm; void main() { int[] aa =[1,2,3,4,5]; aa = aa[0..2] ~aa[3..$]; writeln(aa); //ok

Do you have a better way to remove element from a array?

2015-02-05 Thread FrankLike via Digitalmars-d-learn
Now I can remove element from a array: module removeOne; import std.stdio; import std.array; import std.algorithm; void main() { int[] aa =[1,2,3,4,5]; aa = aa[0..2] ~aa[3..$]; writeln(aa); //ok remove(aa,1); writeln(aa);//get error result } You

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread Tobias Pankrath via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:55:59 UTC, FrankLike wrote: On Thursday, 5 February 2015 at 13:29:30 UTC, Tobias Pankrath wrote: Works as designed: http://dlang.org/phobos/std_algorithm.html#.remove Thank you. aa = remove(aa,1);//ok but how to remove one item? such as aa.remove(2) ? I

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread FrankLike via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:29:30 UTC, Tobias Pankrath wrote: Works as designed: http://dlang.org/phobos/std_algorithm.html#.remove Thank you. aa = remove(aa,1);//ok but how to remove one item? such as aa.remove(2) ?

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread bearophile via Digitalmars-d-learn
Tobias Pankrath: Works as designed: http://dlang.org/phobos/std_algorithm.html#.remove Unfortunately it's one of the worst designed functions of Phobos: https://issues.dlang.org/show_bug.cgi?id=10959 Bye, bearophile

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread bachmeier via Digitalmars-d-learn
On Thursday, 5 February 2015 at 14:09:10 UTC, bearophile wrote: Tobias Pankrath: Works as designed: http://dlang.org/phobos/std_algorithm.html#.remove Unfortunately it's one of the worst designed functions of Phobos: https://issues.dlang.org/show_bug.cgi?id=10959 Bye, bearophile It

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread FrankLike via Digitalmars-d-learn
On Thursday, 5 February 2015 at 14:09:10 UTC, bearophile wrote: Tobias Pankrath: Works as designed: http://dlang.org/phobos/std_algorithm.html#.remove Unfortunately it's one of the worst designed functions of Phobos: https://issues.dlang.org/show_bug.cgi?id=10959 Bye, bearophile

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread FrankLike via Digitalmars-d-learn
On Thursday, 5 February 2015 at 14:09:10 UTC, bearophile wrote: Yes,A.remove(item) or A.removeAt(index) They are better than now.

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread bearophile via Digitalmars-d-learn
bachmeier: It seems your argument is that remove is poorly designed because it's not destructive. Or am I missing your argument? It has to be a void function (or perhaps bettter it can return true/false if it has removed the item, so it becomes @nogc and nothrow). And it has to remove the

Re: Do you have a better way to remove element from a array?

2015-02-05 Thread FG via Digitalmars-d-learn
On 2015-02-05 at 17:25, bearophile wrote: It has to be a void function (or perhaps bettter it can return true/false if it has removed the item, so it becomes @nogc and nothrow). And it has to remove the first item equal to the given one. You can then add a second function that removes at a