Removing an element from an array

H. S. Teoh hsteoh at qfbox.info
Thu Nov 10 23:36:29 UTC 2022


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

-- 
Change is inevitable, except from a vending machine.


More information about the Digitalmars-d-learn mailing list