From a6117dae16cf80e0998834fd4bd2174b60611816 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sun, 30 Nov 2014 19:11:40 +0800 Subject: [PATCH] Fix StringBuffer compilation error in VS2013 Add move constructor and prohibit copy constructor and assignment operator. --- include/rapidjson/stringbuffer.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/stringbuffer.h b/include/rapidjson/stringbuffer.h index b862572d..6ffc1e03 100644 --- a/include/rapidjson/stringbuffer.h +++ b/include/rapidjson/stringbuffer.h @@ -33,11 +33,21 @@ RAPIDJSON_NAMESPACE_BEGIN \note implements Stream concept */ template -struct GenericStringBuffer { +class GenericStringBuffer { +public: typedef typename Encoding::Ch Ch; GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} + GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { + if (&rhs != this) + stack_ = std::move(rhs.stack_); + return *this; + } +#endif + void Put(Ch c) { *stack_.template Push() = c; } void Flush() {} @@ -63,6 +73,11 @@ struct GenericStringBuffer { static const size_t kDefaultCapacity = 256; mutable internal::Stack stack_; + +private: + // Prohibit copy constructor & assignment operator. + GenericStringBuffer(const GenericStringBuffer&); + GenericStringBuffer& operator=(const GenericStringBuffer&); }; //! String buffer with UTF8 encoding