trousers: Support move operator for ScopedTssType
The scoped object would be more useful when it support move.
BUG=b:174816474
TEST=Build OK.
Change-Id: I801c0767b5a19ca0fa844c980e109fc754aca621
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/trousers/+/3583295
Tested-by: Yi Chou <yich@google.com>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Commit-Queue: Yi Chou <yich@google.com>
diff --git a/src/include/trousers/scoped_tss_type.h b/src/include/trousers/scoped_tss_type.h
index caa9141..6f33837 100644
--- a/src/include/trousers/scoped_tss_type.h
+++ b/src/include/trousers/scoped_tss_type.h
@@ -80,8 +80,24 @@
explicit ScopedTssType(TSS_HCONTEXT c = 0, TssType t = 0) :
context_(c),
type_(t) {}
- ScopedTssType(const ScopedTssType&) = delete;
- ScopedTssType& operator=(const ScopedTssType&) = delete;
+
+ ScopedTssType(const ScopedTssType &) = delete;
+ ScopedTssType &operator=(const ScopedTssType &) = delete;
+
+ explicit ScopedTssType(ScopedTssType &&other)
+ : context_(other.context_), type_(other.type_) {
+ other.context_ = 0;
+ other.type_ = 0;
+ }
+
+ ScopedTssType &operator=(ScopedTssType &&other) {
+ release_(context_, type_);
+ context_ = other.context_;
+ type_ = other.type_;
+ other.context_ = 0;
+ other.type_ = 0;
+ return *this;
+ }
virtual ~ScopedTssType() {
release_(context_, type_);