Commit e8082c8c authored by Volker Krause's avatar Volker Krause
Browse files

Add std::hash for AlphaId (and thus IataCode)

parent c358b2e5
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <QString> #include <QString>
#include <cstdint> #include <cstdint>
#include <functional>
namespace KItinerary { namespace KItinerary {
namespace KnowledgeDb { namespace KnowledgeDb {
...@@ -76,6 +77,11 @@ public: ...@@ -76,6 +77,11 @@ public:
return Internal::alphaIdToString(m_id, N); return Internal::alphaIdToString(m_id, N);
} }
/** @internal for std::hash */
inline constexpr T value() const
{
return m_id;
}
private: private:
T m_id = {}; T m_id = {};
}; };
...@@ -91,3 +97,14 @@ inline QDebug operator<<(QDebug dbg, KItinerary::KnowledgeDb::AlphaId<T, N> id) ...@@ -91,3 +97,14 @@ inline QDebug operator<<(QDebug dbg, KItinerary::KnowledgeDb::AlphaId<T, N> id)
return dbg; return dbg;
} }
namespace std {
template <typename T, int N> struct hash<KItinerary::KnowledgeDb::AlphaId<T, N>>
{
typedef KItinerary::KnowledgeDb::AlphaId<T, N> argument_type;
typedef std::size_t result_type;
result_type operator()(argument_type id) const noexcept
{
return std::hash<T>()(id.value());
}
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment