We need to rethink remove in std.container

%u wfunction at hotmail.com
Mon Feb 21 21:04:47 PST 2011


> remove takes a range type which is the range type for the
container that it's on. That makes sense. It's obviously not going
to be able to a take an arbitrary range and remove that from itself.
How would it know which elements in that range corresponded to which
elements in itself - especially when it could be a range which skips
elements or something similar? So, _that_ part makes sense.

I'm wondering, what was the reason for making a "remove range X from
Y" method in the first place? To me, that's not a "remove"
operation; if anything, it's the "removeAll" operation, but I'd
actually call it "subtract" (because it's the set subtraction
operation... although there can be duplicates).

If we change remove to only take in a single element, wouldn't its
implementation then be trivial? (For a range, just return a filter
that removes the element. For a container, actually remove the
element. For ranges that also behave like containers -- like arrays
-- I have no idea.)

Does this sound like a good idea?


More information about the Digitalmars-d mailing list