On Wednesday, 1 August 2012 at 07:44:49 UTC, Ellery Newcomer
wrote:
I also take (erk) issue with the implementation of
linearRemove. It depends on an interface from the container
range that is not part of the general range interface. This
poses problems. You can't wrap the container range with another
range and pass the result to linearRemove. The special
interface is gone. Case in point, there is a specific overload
for Take!Range, which also uses nonstandard interface.
Err, in C++ neither.
If you want to remove an element from a vector, you use
"vector::iterator". A *would be* filter_iterator wouldn't work.
----
Regarding the "special overload", it is only present for
containers that don't provide ranges with opSlice, such as DList.
Now in C++, you'd have both functions for containers:
Remove(it); //Removes element at it
and
Remove(first, last)//removes the range
In D, you also have 1-2 functions, but they carry the same name:
Remove(range); //removes the range.
Remove(Take!Range); //Optional: removes elements from the take
range.
If you compare both, you'll see (IMO) that not only does the
interface provided by D gives just as much functionality for no
extra cost, it also provides MORE functionality:
In the case of forwardRange, remove(Take!Range) can be used to
delete an indiscriminate amount of elements, not just one!
C++ doesn't have that, and neither does java, I believe.
----
But I'll kind of agree, in C++ just like in D, while
iterators/ranges work nice when you manipulate just them, you
always lose a bit of abstraction when you want to re-interface
with the underlying container.