Add move constructor and move operator= to Return<T>.
* Destination object must have isOk() called before moving
* Source object will be safe to destroy (no isOk() is needed) after
moving.
Test: lshal without root no longer fails.
Change-Id: I24648bede7952ec54f9341cdd2ab5d0a0288452a
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 13f0c2c..f3afbc6 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -154,6 +154,16 @@
return_status(const return_status &) = default;
+ return_status(return_status &&other) {
+ *this = std::move(other);
+ }
+ return_status &operator=(return_status &&other) {
+ checkStatus();
+ std::swap(mStatus, other.mStatus);
+ std::swap(mCheckedStatus, other.mCheckedStatus);
+ return *this;
+ }
+
~return_status();
bool isOk() const {
@@ -178,6 +188,12 @@
Return(const Return &) = default;
+ // move-able.
+ // precondition: "this" has checked status
+ // postcondition: other is safe to destroy after moving to *this.
+ Return(Return &&other) = default;
+ Return &operator=(Return &&) = default;
+
~Return() = default;
operator T() const {
@@ -199,6 +215,13 @@
Return(Status s) : details::return_status(s) {}
Return(const Return &) = default;
+
+ // move-able.
+ // precondition: "this" has checked status
+ // postcondition: other is safe to destroy after moving to *this.
+ Return(Return &&other) = default;
+ Return &operator=(Return &&) = default;
+
~Return() = default;
operator sp<T>() const {
@@ -215,6 +238,12 @@
Return(const Return &) = default;
+ // move-able.
+ // precondition: "this" has checked status
+ // postcondition: other is safe to destroy after moving to *this.
+ Return(Return &&) = default;
+ Return &operator=(Return &&) = default;
+
~Return() = default;
};