How to safely delete entries from a queue

In reply to dave_59:

Hi Dave,

The code below looks similar to what I mentioned in my original post except that the id_q[$] is now declared as an array. Are you suggesting that this should work?

// alternatively if you expect large arrays and small number of matching items
int index_cu[$];
 
index_cu      = id_aa.find_index() with (item == 'h1b);
foreach(index_cu[i]) 
   id_aa.delete(index_cu[i]);

and could you explain how the code below works ?

for(int i = 0; i<id_q.size(); i++)
  if(id_q[i] == 'h1b)
    id_q.delete(i--);