I have a set of shared_ptr
and would like to find a value in it:
typedef std::shared_ptr<int> IntPtr;
struct Compare {
bool operator() (const IntPtr& a, const IntPtr& b) {
return *a < *b;
}
};
std::set<IntPtr, Compare> s;
auto x = std::make_shared<int>(3);
s.insert(x);
bool found = s.find(std::make_shared<int>(3)) != s.end();
It's working, but not efficient - it need to new a temp pointer every time when trying to find a value.
Is there any other way for it?
Looks like Searching in a set of shared_ptr<QString> has some ideas that might help?