Do we have a simple find/remove algorithm?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Sep 26 12:22:52 UTC 2020


On 9/25/20 11:45 PM, mipri wrote:
> On Saturday, 26 September 2020 at 02:48:54 UTC, H. S. Teoh wrote:
>> On Fri, Sep 25, 2020 at 10:29:57PM -0400, Andrei Alexandrescu via 
>> Digitalmars-d wrote:
>>> "Find it and kill it" seems rather tedious to do. We have 
>>> https://dlang.org/library/std/algorithm/mutation/remove.html, which 
>>> operates with either indices or predicates. Then we have find and 
>>> findSplitXxx, but neither seems to make it easy to find some element 
>>> and remove it by shifting the range backwards. What am I missing?
>>
>> It's a bit wordy, true, but I wouldn't say it's _tedious_ per se:
>>
>>     import std;
>>     void main() {
>>         auto data = [ 1,2,3,4,5 ];
>>         data = data.remove!(x => x == 3);
>>         writeln(data);
>>     }
>>
>>
>> T
> 
> This removes two elements however:
> 
> [1,2,3,4,5,3].remove!(x => x==3)

Yah, removing all is not too difficult. Removing one is oddly missing. I 
think we should add a findRemove algorithm. Question is, should it go in 
iteration.d or mutation.d? :o)

Also, loosely related: findSplitXxx does not work for finding individual 
elements, only (sub)ranges.


More information about the Digitalmars-d mailing list