BString: add support for move semantics with C++11 and up.

This implements the "rule of 5" for this type. While the copy operation for
BString was already using shallow copies of the underlying data, this change
further optimizes moving the data from one object to another.

While it is not the intention to implement move semantics to all types in the
legacy Haiku/Be kits, data types like BString are good candidates, because move
operations are often useful when working with data within an application.

In this implementation, the internal data of the string object will be set to
NULL, thus leaving an empty string.

Change-Id: I16bf9424f9b17f622b0b57659b80628e18760288
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4428
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
Niels Sascha Reedijk
2021-09-08 07:07:36 +00:00
committed by Jérôme Duval
parent 3cf06bfc6b
commit 0b86520c4d
6 changed files with 88 additions and 4 deletions
+6
View File
@@ -22,6 +22,9 @@ public:
BString(const char* string);
BString(const BString& string);
BString(const char* string, int32 maxLength);
#if __cplusplus >= 201103L
BString(BString&& string);
#endif
~BString();
// Access
@@ -39,6 +42,9 @@ public:
BString& operator=(const BString& string);
BString& operator=(const char* string);
BString& operator=(char c);
#if __cplusplus >= 201103L
BString& operator=(BString&& string);
#endif
BString& SetTo(const char* string);
BString& SetTo(const char* string, int32 maxLength);