[ox/std] Add UUID::isNull()
This commit is contained in:
parent
3510e38ae5
commit
c75ff7881f
3
deps/ox/src/ox/std/uuid.cpp
vendored
3
deps/ox/src/ox/std/uuid.cpp
vendored
@ -34,4 +34,7 @@ Result<UUID> UUID::generate() noexcept {
|
||||
return out;
|
||||
}
|
||||
|
||||
static_assert(UUID{}.isNull());
|
||||
static_assert(!UUID::fromString("34AF4809-043D-4348-B720-2B454E5678C7").value.isNull());
|
||||
|
||||
}
|
||||
|
18
deps/ox/src/ox/std/uuid.hpp
vendored
18
deps/ox/src/ox/std/uuid.hpp
vendored
@ -107,6 +107,22 @@ class UUID {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto isNull() const noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
for (auto v : m_value) {
|
||||
if (v) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
constexpr uint64_t zero = 0;
|
||||
return ox::memcmp(&zero, m_value.data() + 0, 8) == 0
|
||||
&& ox::memcmp(&zero, m_value.data() + 8, 8) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr ox::Result<ox::UUID> fromString(ox::CRStringView s) noexcept {
|
||||
if (s.len() < 36) {
|
||||
return OxError(1, "Insufficient data contain complete UUID");
|
||||
@ -135,7 +151,7 @@ class UUID {
|
||||
UUIDStr out;
|
||||
auto valueI = 0u;
|
||||
constexpr auto printChars = [](
|
||||
ox::BString<36> *out,
|
||||
UUIDStr *out,
|
||||
const Array<uint8_t, 16> &value,
|
||||
std::size_t cnt,
|
||||
unsigned valueI) {
|
||||
|
Loading…
Reference in New Issue
Block a user