Remove item from list using pointer

I have a pointer p(not an iterator) to an item in a list. Can I use pto remove (delete) an item from a list? Sort of:

mylist.erase(p);

So far, I have been able to do this by sorting through the list until I reach the item in the location p, and then using a method erasethat seems very inefficient.

+5
source share
4 answers

A is std::listnot associative, so you cannot use a pointer as a key to simply delete a specific element directly.

, , , , , , - (.. )

, :

  • , std::multiset ( ), .

  • , , , "" ( ), , . , .

  • , (< 20 .) , , , , " ", . , , -.

, 3, , .:)

+3

, . , , , ...

+8

, , :

, undefined :

T* list<T>. std library list. Gnu g++ stl_list.h, std::list . std::list<T> , :

template <class T>
struct Node {
   T item;
   Node* prev;
   Node* next;
};

Node<T>::item, offsetof node. , Node std::list, - , . std::list<>::iterator Node.

0

.

, epoll_wait . , void *, , ( ), .

, std:: list , , , .

LIST Linux, . , apis .

0

All Articles