Removing an element from an array

Alexander Zhirov azhirov1991 at gmail.com
Thu Nov 10 23:26:45 UTC 2022


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
```

In the pros, I would do it this way, for example via lambda

```c++
arr.erase(std::find_if(arr.cbegin(), arr.cend(), [&](const 
std::reference_wrapper<A> &item)
{
     return &item.get() == &fragment;
}));
```


More information about the Digitalmars-d-learn mailing list