Adding swap() for GenericMember
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 @@
}
struct NameComparator {
- bool operator()(
- const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
- const GenericMember<UTF8<>, 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 @@
struct GenericMember {
GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
GenericValue<Encoding, Allocator> 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);
+ }
};
///////////////////////////////////////////////////////////////////////////////