Std :: vector from std :: weak_ptr and std :: find

I am currently trying to replace some parts of my code with std :: shared_ptr and std :: weak_ptr. In many parts I have std :: vectors from std :: weak_ptrs (which used to be raw ptrs) and use std :: find to find a specific pointer in an array. This does not work with weak pointers as they do not implement the == operators for various reasons. I have to stick with std :: weak_ptr to avoid circular dependencies. What are my options, should I revert to using raw pointers instead of weak pointers?

Example

//_window is a shared_ptr that I want to find in a vector of weak_ptrs
WindowWeakPtrArray::iterator it = std::find(m_windows.begin(), m_windows.end(), _window); 

      

thank

+3


source to share


1 answer


Without considering the construction, you can use std::find_if

using a special comparator that checks for validity weak_ptr

and then compares the internal pointers, if any.



+9


source







All Articles