Removing an element from a DList
monkyyy
crazymonkyyy at gmail.com
Tue Oct 17 18:57:54 UTC 2023
On Tuesday, 17 October 2023 at 17:27:19 UTC, Joakim G. wrote:
> For some reason I cannot remove an element from a DList. I
> tried several range approaches but to no avail. I'm a noob.
>
> In the end I did this:
>
> ```
> private void removeFromWaitingQueue(uint jid) {
> auto arr = waitingQueue[].array;
> arr = arr.remove!(job => job.jid == jid);
> waitingQueue.clear();
> foreach(job; arr) {
> waitingQueue.insertBack(job);
> }
> }
> ```
>
> Any hints?
>
> /J
"ranges are views of data" blah blah blah that remove function
returns a fancy pointer and is lazy not the sane eager "unsafe"
thing, the std avoids mutation to an unhelpful degree also
std.containeers is awful
Id suggest using dynamic arrays swapping the last element to
index then length--; or nullable static arrays; or just using
filter if a functional approach is on the table.
More information about the Digitalmars-d-learn
mailing list