mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-20 06:04:36 +00:00
added template hash
This commit is contained in:
@@ -265,13 +265,14 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // 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")]]
|
[[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;
|
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.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
|
|||||||
@@ -318,14 +318,15 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // 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
|
// NOTE: Cannot be constexpr because of MSVC
|
||||||
[[nodiscard("You must use hash value")]]
|
[[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;
|
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.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
|
|||||||
@@ -225,13 +225,14 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // 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")]]
|
[[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;
|
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.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 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;
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user