I just found out, to my surprise, that the following code does not compile out of the box in C++14 using Qt 5.4:
QSet<std::shared_ptr<SomeType>> var;
The problem is that there is no overload of the qHash()
method for std::shared_ptr
, or any other smart pointer as far as I can see:
http://doc.qt.io/qt-5/qhash.html#related-non-members
It seems natural to me to have the following overload (or something similar):
template <typename T>
uint qHash(const std::shared_ptr<T>& ptr, uint seed = 0)
{
return qHash(ptr.get(), seed);
}
but it does not exist. This cannot simply be something the Qt developers overlooked. Do I need to include a special header? What is the reason why this does not exist?