added template hash

This commit is contained in:
va_alpatov
2026-06-19 01:01:27 +03:00
parent 8a591ce769
commit a546c1a6d1
3 changed files with 12 additions and 10 deletions
+4 -3
View File
@@ -265,13 +265,14 @@ namespace omath
};
} // namespace omath
template<> struct std::hash<omath::Vector2<float>>
template<class Type>
struct std::hash<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
{
[[nodiscard("You must use hash value")]]
std::size_t operator()(const omath::Vector2<float>& vec) const noexcept
std::size_t operator()(const omath::Vector2<Type>& vec) const noexcept
{
std::size_t hash = 0;
constexpr std::hash<float> hasher;
constexpr std::hash<Type> hasher;
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
+4 -3
View File
@@ -318,14 +318,15 @@ namespace omath
};
} // namespace omath
template<> struct std::hash<omath::Vector3<float>>
template<class Type>
struct std::hash<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
{
// NOTE: Cannot be constexpr because of MSVC
[[nodiscard("You must use hash value")]]
std::size_t operator()(const omath::Vector3<float>& vec) const noexcept
std::size_t operator()(const omath::Vector3<Type>& vec) const noexcept
{
std::size_t hash = 0;
constexpr std::hash<float> hasher;
constexpr std::hash<Type> hasher;
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
+4 -4
View File
@@ -225,13 +225,14 @@ namespace omath
};
} // namespace omath
template<> struct std::hash<omath::Vector4<float>>
template<class Type>
struct std::hash<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
{
[[nodiscard("You must use hash value")]]
std::size_t operator()(const omath::Vector4<float>& vec) const noexcept
std::size_t operator()(const omath::Vector4<Type>& vec) const noexcept
{
std::size_t hash = 0;
constexpr std::hash<float> hasher;
constexpr std::hash<Type> hasher;
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
@@ -240,7 +241,6 @@ template<> struct std::hash<omath::Vector4<float>>
return hash;
}
};
template<class Type>
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
{