light/modules/ecs/public/uuid.hpp

39 lines
488 B
C++
Raw Permalink Normal View History

2025-07-05 13:28:41 +03:30
#pragma once
#include <random>
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
class UUID
{
public:
UUID(uint64_t uuid = -1);
operator uint64_t() const
{
return m_uuid;
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
private:
static std::mt19937_64 s_engine;
static std::uniform_int_distribution<uint64_t> s_distribution;
uint64_t m_uuid;
2025-07-05 13:28:41 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt
2025-07-05 13:28:41 +03:30
namespace std {
template<>
2025-07-11 00:05:48 +03:30
struct hash<lt::UUID>
2025-07-05 13:28:41 +03:30
{
2025-07-11 00:05:48 +03:30
std::size_t operator()(const lt::UUID &uuid) const
2025-07-05 13:28:41 +03:30
{
return hash<uint64_t>()(static_cast<uint64_t>(uuid));
}
};
} // namespace std