From 7ddbd1643e52e2c6b2f2a7842a8f3d8e8d5985dc Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Sun, 5 Jan 2025 14:36:29 +0000 Subject: [PATCH] Codechange: Implementation of std::hash for StrongType::Typedef --- src/core/strong_typedef_type.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/core/strong_typedef_type.hpp b/src/core/strong_typedef_type.hpp index a89ec0460f..e818228d50 100644 --- a/src/core/strong_typedef_type.hpp +++ b/src/core/strong_typedef_type.hpp @@ -158,4 +158,31 @@ namespace StrongType { }; } +/** + * Implementation of std::hash for StrongType::Typedef. + * + * This specialization of std::hash allows hashing of StrongType::Typedef instances + * by leveraging the hash of the base type. + * + * Example Usage: + * using MyType = StrongType::Typedef; + * std::unordered_map my_map; + * + * @tparam TBaseType The underlying type of the StrongType::Typedef. + * @tparam TProperties Additional properties for the StrongType::Typedef. + */ +template +struct std::hash> { + /** + * Computes the hash value for a StrongType::Typedef instance. + * + * @param t The StrongType::Typedef instance to hash. + * @return The hash value of the base type of t. + */ + std::size_t operator()(const StrongType::Typedef &t) const noexcept + { + return std::hash()(t.base()); + } +}; + #endif /* STRONG_TYPEDEF_TYPE_HPP */