mercredi 25 novembre 2020

Remove a list item from list in the item's member function (C++ STL)

Say I have a list list<Item>, and

class Item {
 public:
  Item(list<Item>& l); // l is the list the item is in.

  RemoveItself() {...} // remove this from l.
}

when I call item.RemoveItself(), it remove itself from the list. If I were to implement myself, I could have prev_ptr and next_ptr in the Item, and then everything is easy. I am wondering if there is a way to do it using STL?

Thanks!

Aucun commentaire:

Enregistrer un commentaire