The best way to remove an element from DList while iterating over the elements

Ivan helloitsme at example.com
Mon Aug 31 21:29:50 UTC 2020


Hello!

I've been trying to implement something like that:

struct Element
{
     bool isPendingRelease;
}

DList!Element elements;

void FreePendingElements()
{
     foreach(ref elem; elements)
     {
         if (elem.isPendingRelease)
         {
             // remove it here from elements
         }
     }
}

What's the best way to implement the logic I want?

Thanks,
Ivan



More information about the Digitalmars-d-learn mailing list