Removing an element from an array

Alexander Zhirov azhirov1991 at gmail.com
Fri Nov 11 00:02:09 UTC 2022


On Thursday, 10 November 2022 at 23:36:29 UTC, H. S. Teoh wrote:
> On Thu, Nov 10, 2022 at 11:26:45PM +0000, Alexander Zhirov via 
> Digitalmars-d-learn wrote:
>> I have an array of self-written class `A`. I'm sorry for my 
>> tactlessness, but I'm confused about the modules. How do I 
>> correctly find a specific object `fragment` inside the array 
>> and delete it? I don't quite understand which modules to use 
>> to do this optimally.
>> 
>> ```d
>> A[] arr;
>> A fragment = new A;
>> ...
>> arr.remove(fragment);  // Something like
>> ```
>
> I would do something like this:
>
> 	// Warning: untested code
> 	import std.algorithm;
> 	arr = arr.remove(arr.countUntil(fragment));
>
>
> T

As always - simple and compact. Thank you:)


More information about the Digitalmars-d-learn mailing list