From 5e2c8fb089fdc5c1dfb36e22d25ae803fedee1ae Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 22 Jan 2025 20:01:45 +0100 Subject: [PATCH] util/StringWithHash: add nullptr constructor --- src/util/StringWithHash.hxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/StringWithHash.hxx b/src/util/StringWithHash.hxx index 5bf4c0a7..1d595712 100644 --- a/src/util/StringWithHash.hxx +++ b/src/util/StringWithHash.hxx @@ -26,6 +26,17 @@ struct StringWithHash { explicit constexpr StringWithHash(std::string_view _value, std::size_t _hash) noexcept :hash(_hash), value(_value) {} + /** + * Construct a "nulled" instance, i.e. one where IsNull() + * returns true. + */ + explicit constexpr StringWithHash(std::nullptr_t) noexcept + :value() {} + + constexpr bool IsNull() const noexcept { + return value.data() == nullptr; + } + constexpr bool operator==(const StringWithHash &) const noexcept = default; };