Added move semantics to FString class

This commit is contained in:
alexey.lysiuk 2017-10-23 11:48:04 +03:00
parent 7d97963005
commit 3e43572a87
2 changed files with 17 additions and 0 deletions

View file

@ -211,6 +211,21 @@ FString &FString::operator = (const FString &other)
} }
return *this; return *this;
} }
FString &FString::operator = (FString &&other)
{
assert (Chars != NULL);
if (&other != this)
{
Data()->Release();
Chars = other.Chars;
other.ResetToNull();
}
return *this;
}
FString &FString::operator = (const char *copyStr) FString &FString::operator = (const char *copyStr)
{ {
if (copyStr != Chars) if (copyStr != Chars)

View file

@ -124,6 +124,7 @@ public:
// Copy constructors // Copy constructors
FString (const FString &other) { AttachToOther (other); } FString (const FString &other) { AttachToOther (other); }
FString (FString &&other) : Chars(other.Chars) { other.ResetToNull(); }
FString (const char *copyStr); FString (const char *copyStr);
FString (const char *copyStr, size_t copyLen); FString (const char *copyStr, size_t copyLen);
FString (char oneChar); FString (char oneChar);
@ -165,6 +166,7 @@ public:
const char &operator[] (unsigned long long index) const { return Chars[index]; } const char &operator[] (unsigned long long index) const { return Chars[index]; }
FString &operator = (const FString &other); FString &operator = (const FString &other);
FString &operator = (FString &&other);
FString &operator = (const char *copyStr); FString &operator = (const char *copyStr);
FString operator + (const FString &tail) const; FString operator + (const FString &tail) const;