Add move assignment operator to SwigValueWrapper

Closes #2039
This commit is contained in:
William S Fulton 2022-06-15 08:45:29 +01:00
commit 088dc6e870
5 changed files with 273 additions and 0 deletions

View file

@ -663,6 +663,7 @@ namespace std {
#ifdef __cplusplus
%insert("runtime") %{
#ifdef __cplusplus
#include <utility>
/* SwigValueWrapper is described in swig.swg */
template<typename T> class SwigValueWrapper {
struct SwigMovePointer {
@ -676,6 +677,9 @@ template<typename T> class SwigValueWrapper {
public:
SwigValueWrapper() : pointer(0) { }
SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
#if __cplusplus >= 201103L
SwigValueWrapper& operator=(T&& t) { SwigMovePointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
#endif
operator T&() const { return *pointer.ptr; }
T *operator&() { return pointer.ptr; }
};%}