Why is std.algorithm so complicated to use?
Mehrdad
wfunction at hotmail.com
Sun Jul 15 15:22:38 PDT 2012
On Sunday, 15 July 2012 at 22:03:33 UTC, Jonathan M Davis wrote:
> auto arr = [10, 22, 19, 4, 6];
> arr = remove(arr, 3);
> assert(arr == [10, 22, 19, 6]);
Yeah, the problem is that this reallocates... (not claiming
remove() itself is supposed to be efficient, but this is making
it even worse)
> The main problem is understanding why remove (or erase in C++)
> works this way, which seems to throw off a bunch of people in
> both D and C++, but it's something that we're pretty much stuck
> with. You need the actual container (not an iterator or range)
> if you want to actually remove the element.
Well, for arrays, the "actual container" is the array, so that
doesn't work either. :\ On the other hand, even C++ has
vector<T>::erase()!
More information about the Digitalmars-d
mailing list