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

FG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 5 10:26:41 PST 2015


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 given index (like removeAt).

I was never a fan of STL's erase-remove idiom, although the decoupling of algorithms and containers is in general a great idea. However, in D algorithms can be smarter, because they operate on ranges instead of iterators. I don't see why remove has to follow the C++ example. Therefore I have to ask:

Is there any reason why `remove` doesn't take the range by reference and `popBack` as many elements as were removed?


More information about the Digitalmars-d-learn mailing list