[ox/std] Add UUID::isNull()

This commit is contained in:
Gary Talent 2023-03-03 23:24:38 -06:00
parent 3510e38ae5
commit c75ff7881f
2 changed files with 20 additions and 1 deletions

View File

@ -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());
}

View File

@ -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) {