String: Add operator=
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-07 12:14:21 +02:00
parent 4cac49038c
commit 0f678f845c
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,9 @@ class String
String(String&&);
String(const String&) = delete;
String& operator=(String&&);
String& operator=(const String&) = delete;
~String();
Result<String> clone() const;

View File

@ -23,6 +23,24 @@ String::String(String&& other)
other.m_string = nullptr;
}
String& String::operator=(String&& other)
{
if (&other == this) return *this;
if (!m_inline) free_impl(m_string);
m_inline = other.m_inline;
m_string = other.m_string;
m_length = other.m_length;
if (m_inline) memcpy(m_inline_storage, other.m_inline_storage, sizeof(m_inline_storage));
other.m_string = nullptr;
return *this;
}
String::String(char* c_str)
{
check(c_str);