maarten van damme:
But remove doesn't truly remove from the source range because
the length of
the source range stays the same. It's return value is a
modified copy of
the source range.
Filter doesn't really work right away because that would also
remove
duplicate elements while I only want to remove at a given
index. It also
makes for clunkier looking code and is counterintinuitive to
come up with
(I want to remove an element therefore I have to filter every
element that
isn't equal to that element from the source range...)
And while I haven't worked in c++, even that appears to have
remove_copy
which is really what I want.
I agree that the design of std.algorithm.remove is bug prone. The
compiler doesn't verify that you are using its result! I have
also filed several bugs regarding the implementation of
std.algorithm.remove.
In the end your complaints are real. You can't expect Phobos to
be perfect, but people work to fix it. Fixing such problems
future D users will not find your problem. So I suggest you to
think well about what your problem is, what you don't like on
this, and then write a enhancement request for Phobos. Even if
std.algorithm.remove can't be fixed, people can add a new
function with a safer/more handy behavour.
Bye,
bearophile