13 using ValueType = uint32_t;
15 static constexpr uint32_t index_bits = 24;
16 static constexpr uint32_t version_bits = 8;
17 static constexpr ValueType IndexMask = (1u << index_bits) - 1;
18 static constexpr ValueType VersionMask = (1u << version_bits) - 1;
21 : value_(Invalid().value_)
24 constexpr EntityId(uint32_t index, uint32_t version) noexcept
25 : value_((version << index_bits) | (index & IndexMask))
29 static constexpr EntityId Invalid()
noexcept
31 return EntityId(std::numeric_limits<ValueType>::max());
34 static constexpr EntityId FromRaw(ValueType raw)
noexcept
39 [[nodiscard]]
constexpr uint32_t Index()
const noexcept
41 return value_ & IndexMask;
44 [[nodiscard]]
constexpr uint32_t Version()
const noexcept
46 return (value_ >> index_bits) & VersionMask;
49 [[nodiscard]]
constexpr ValueType Raw()
const noexcept
54 constexpr bool operator==(
const EntityId& other)
const noexcept =
default;
55 constexpr bool operator!=(
const EntityId& other)
const noexcept =
default;
57 constexpr explicit operator bool()
const noexcept
59 return value_ != Invalid().value_;
63 explicit constexpr EntityId(ValueType raw) noexcept