From 3f3438093dc6b085ad86c8b728aeee1b733c433a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Nov 2021 02:06:08 +0100 Subject: [PATCH] Define move ctor and assignment operator for C++ wrappers This can be done naturally and there doesn't seem to be any reason not to do it. --- Source/Modules/c.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 633e34558..c0ea65a91 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -571,6 +571,28 @@ public: NIL ); + // OTOH we may always provide move ctor and assignment, as we can always implement them trivially ourselves. + if (first_base_) { + Printv(cxx_wrappers_.f_decls, + cindent, classname, "(", classname, "&& obj) = default;\n", + cindent, classname, "& operator=(", classname, "&& obj) = default;\n", + NIL + ); + } else { + Printv(cxx_wrappers_.f_decls, + cindent, classname, "(", classname, "&& obj) : " + "swig_self_{obj.swig_self_}, swig_owns_self_{obj.swig_owns_self_} { " + "obj.swig_owns_self_ = false; " + "}\n", + cindent, classname, "& operator=(", classname, "&& obj) { " + "swig_self_ = obj.swig_self_; swig_owns_self_ = obj.swig_owns_self_; " + "obj.swig_owns_self_ = false; " + "return *this; " + "}\n", + NIL + ); + } + // We also need a swig_self() method for accessing the C object pointer. Printv(cxx_wrappers_.f_decls, cindent, c_class_ptr.get(), " swig_self() const noexcept ",