From b94c2a12033362ec41ca5e5d65fb9d3e10da16e8 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 8 Feb 2019 11:39:25 +0800 Subject: [PATCH] Adding swap() for GenericMember --- example/sortkeys/sortkeys.cpp | 5 +---- include/rapidjson/document.h | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/example/sortkeys/sortkeys.cpp b/example/sortkeys/sortkeys.cpp index 022a6a4..72a6410 100644 --- a/example/sortkeys/sortkeys.cpp +++ b/example/sortkeys/sortkeys.cpp @@ -17,10 +17,7 @@ static void printIt(const Value &doc) { } struct NameComparator { - bool operator()( - const GenericMember, MemoryPoolAllocator<> > &lhs, - const GenericMember, MemoryPoolAllocator<> > &rhs) const - { + bool operator()(const Value::Member &lhs, const Value::Member &rhs) const { return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); } }; diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 73afea6..d1b90eb 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -66,6 +66,12 @@ template struct GenericMember { GenericValue name; //!< name of member (must be a string) GenericValue value; //!< value of member. + + // swap() for std::sort() and other potential use in STL. + friend inline void swap(GenericMember& a, GenericMember& b) RAPIDJSON_NOEXCEPT { + a.name.Swap(b.name); + a.value.Swap(b.value); + } }; ///////////////////////////////////////////////////////////////////////////////