From: Manuel Nickschas Date: Mon, 15 Oct 2018 19:22:04 +0000 (+0200) Subject: types: Add STL-compliant Hash functor for Qt types X-Git-Tag: test-travis-01~107 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=55ed2b3b4fac69d7d4bcb62f312b1fd233626577;hp=b8db3c55a7f66a8d6ecabf9039aabceff9ae4837 types: Add STL-compliant Hash functor for Qt types In order to use Qt types with std::unordered_set (and map), a compatible hash function needs to be provided. Provide a generic Hash functor that just uses the qHash() function for the given type. This can be used as follows: std::unordered_set> set; --- diff --git a/src/common/types.h b/src/common/types.h index a806c58f..0816223d 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -225,6 +225,16 @@ QDataStream& operator>>(QDataStream& in, T& value) return in; } +// STL-compliant hash functor for Qt types +template +struct Hash +{ + uint operator()(const T& t) const + { + return qHash(t); + } +}; + // Exceptions /**