From b5f9d6076596c5c2b14daa99c33fc01fa69b54e0 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sun, 31 Aug 2014 17:23:15 +0200 Subject: [PATCH] GenericValue: add rvalue-ref overloads to AddMember/PushBack Directly allows temporary GenericValues as parameters: v.AddMember("foo", Value(s.c_str(),alloc), alloc); --- include/rapidjson/document.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 5487918..b6edb4a 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -911,6 +911,23 @@ public: return *this; } +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) { + return AddMember(name, value, allocator); + } + GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) { + GenericValue n(name); + return AddMember(n, value, allocator); + } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + + //! Add a member (name-value pair) to the object. /*! \param name A constant string reference as name of member. \param value Value of any type. @@ -1151,6 +1168,12 @@ int z = a[0u].GetInt(); // This works too. return *this; } +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + GenericValue& PushBack(GenericValue&& value, Allocator& allocator) { + return PushBack(value, allocator); + } +#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Append a constant string reference at the end of the array. /*! \param value Constant string reference to be appended. \param allocator Allocator for reallocating memory. It must be the same one used previously. Commonly use GenericDocument::GetAllocator().