totally_ordered_wrapper: add swap and qHash overloads; std::hash specialization
Pointers have these. We also have qt_ptr_hash for raw pointers, so add an ADL overload for that, too. Don't provide a member-swap, since raw pointers don't have that. Change-Id: I1517588d2ff1aa5caf06ad5861ff09d5e7652183 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
d397ae4c06
commit
5831c31235
@ -23,7 +23,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <QtCore/q20type_traits.h>
|
#include <QtCore/q20type_traits.h>
|
||||||
|
|
||||||
#include <functional> // std::less
|
#include <functional> // std::less, std::hash
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -653,10 +653,27 @@ private:
|
|||||||
MAKE_RELOP(auto, <=>, compare_three_way)
|
MAKE_RELOP(auto, <=>, compare_three_way)
|
||||||
#endif
|
#endif
|
||||||
#undef MAKE_RELOP
|
#undef MAKE_RELOP
|
||||||
|
friend void qt_ptr_swap(totally_ordered_wrapper &lhs, totally_ordered_wrapper &rhs) noexcept
|
||||||
|
{ qt_ptr_swap(lhs.ptr, rhs.ptr); }
|
||||||
|
friend void swap(totally_ordered_wrapper &lhs, totally_ordered_wrapper &rhs) noexcept
|
||||||
|
{ qt_ptr_swap(lhs, rhs); }
|
||||||
|
friend size_t qHash(totally_ordered_wrapper key, size_t seed = 0) noexcept
|
||||||
|
{ return qHash(key.ptr, seed); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} //Qt
|
} //Qt
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template <typename P>
|
||||||
|
struct hash<QT_PREPEND_NAMESPACE(Qt::totally_ordered_wrapper)<P>>
|
||||||
|
{
|
||||||
|
using argument_type = QT_PREPEND_NAMESPACE(Qt::totally_ordered_wrapper)<P>;
|
||||||
|
using result_type = size_t;
|
||||||
|
constexpr result_type operator()(argument_type w) const noexcept
|
||||||
|
{ return std::hash<P>{}(w.get()); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QCOMPAREHELPERS_H
|
#endif // QCOMPAREHELPERS_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user