Remove from a std::set<shared_ptr<T>> by T*
Posted
by Autopulated
on Stack Overflow
See other posts from Stack Overflow
or by Autopulated
Published on 2010-03-28T10:57:20Z
Indexed on
2010/03/28
11:03 UTC
Read the original article
Hit count: 261
I have a set of shared pointers:
std::set<boost::shared_ptr<T>> set;
And a pointer:
T* p;
I would like to efficiently remove the element of set
equal to p
, but I can't do this with any of the members of set, or any of the standard algorithms, since T*
is a completely different type to boost::shared_ptr<T>
.
A few approaches I can think of are:
- somehow constructing a new shared_ptr from the pointer that won't take ownership of the pointed to memory (ideal solution, but I can't see how to do this)
- wrapping / re-implementing shared_ptr so that I can do the above
- just doing my own binary search over the set
Help!
© Stack Overflow or respective owner