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); + } }; ///////////////////////////////////////////////////////////////////////////////