From 1beec85453448a7186a01a1bb16848d90afe6908 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sun, 31 Aug 2014 12:25:00 +0200 Subject: [PATCH] GenericValue: add move constructor/move assignment When C++11 is enabled, several algorithms will fail, if GenericValue is neither copyable, nor movable. Cherry-picked from 8005b55. --- include/rapidjson/document.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 92c7316..044a8fd 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -416,6 +416,13 @@ public: //! Default constructor creates a null value. GenericValue() : data_(), flags_(kNullFlag) {} +#ifdef RAPIDJSON_CXX11 + //! Move constructor in C++11 + GenericValue(GenericValue&& rhs) : data_(rhs.data_), flags_(rhs.flags_) { + rhs.flags_ = kNullFlag; // give up contents + } +#endif + private: //! Copy constructor is not permitted. GenericValue(const GenericValue& rhs); @@ -567,6 +574,13 @@ public: return *this; } +#ifdef RAPIDJSON_CXX11 + //! Move assignment in C++11 + GenericValue& operator=(GenericValue&& rhs) { + return *this = rhs.Move(); + } +#endif + //! Assignment of constant string reference (no copy) /*! \param str Constant string reference to be assigned \note This overload is needed to avoid clashes with the generic primitive type assignment overload below.