From 0ded23591bba9ce68ce813f54290734f1b4dcd3f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Jan 2021 13:35:24 +0100 Subject: [PATCH] util/AllocatedString: add operator=() --- src/util/AllocatedString.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/AllocatedString.hxx b/src/util/AllocatedString.hxx index 9b2c5812a..f2bc4f4fa 100644 --- a/src/util/AllocatedString.hxx +++ b/src/util/AllocatedString.hxx @@ -100,6 +100,18 @@ public: return *this; } + BasicAllocatedString &operator=(std::string_view src) noexcept { + delete[] std::exchange(value, nullptr); + value = Duplicate(src); + return *this; + } + + BasicAllocatedString &operator=(const char *src) noexcept { + delete[] std::exchange(value, nullptr); + value = src != nullptr ? Duplicate(src) : nullptr; + return *this; + } + constexpr bool operator==(std::nullptr_t) const noexcept { return value == nullptr; } @@ -161,6 +173,8 @@ public: AllocatedString() noexcept = default; AllocatedString(BasicAllocatedString &&src) noexcept :BasicAllocatedString(std::move(src)) {} + + using BasicAllocatedString::operator=; }; #endif