Browse Source

added move assignment operator

DhruvMaroo 4 years ago
parent
commit
bdc5674ace
2 changed files with 7 additions and 0 deletions
  1. 1 0
      include/core/String.hpp
  2. 6 0
      src/core/String.cpp

+ 1 - 0
include/core/String.hpp

@@ -56,6 +56,7 @@ public:
 	wchar_t operator[](const int idx) const;
 	wchar_t operator[](const int idx) const;
 
 
 	void operator=(const String &s);
 	void operator=(const String &s);
+	void operator=(String&& s);
 	bool operator==(const String &s) const;
 	bool operator==(const String &s) const;
 	bool operator!=(const String &s) const;
 	bool operator!=(const String &s) const;
 	String operator+(const String &s) const;
 	String operator+(const String &s) const;

+ 6 - 0
src/core/String.cpp

@@ -99,6 +99,12 @@ void String::operator=(const String &s) {
 	godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
 	godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
 }
 }
 
 
+void String::operator=(String&& s) {
+	godot::api->godot_string_destroy(&_godot_string);
+	godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
+	godot::api->godot_string_destroy(&s._godot_string);
+}
+
 bool String::operator==(const String &s) const {
 bool String::operator==(const String &s) const {
 	return godot::api->godot_string_operator_equal(&_godot_string, &s._godot_string);
 	return godot::api->godot_string_operator_equal(&_godot_string, &s._godot_string);
 }
 }