
Szczepan Hołyszewski skrev:
I have a pointer to an object that is in a ptr_list, and I want to "detach" the object from the list without deleting it.
Problem: ptr_list::release() wants an iterator, not a pointer.
A naive attempt at std::finding the iterator fails because ptr_list's indirection kicks in and std::find ends up wanting to compare values instead of pointers. Luckily my objects aren't equality comparable so I get a compile error instead of an elusive bug. As a workaround I just walk the list with BOOST_FOREACH() but it feels kludgy.
Is there a "designed" way to feed a ptr_list an element pointer and milk the corresponding iterator?
No, you have to search for it.
Is there a direct way do detach an item from ptr_list without deleting it?
Did I overlook something obvious?
You can compare pointers by using std::find( cont.begin().base(), cont.end().base(), ptr ); .base() returns the wrapped containers iterator. -Thorsten