diff options
author | Milo Yip <miloyip@gmail.com> | 2019-02-08 11:39:25 +0800 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2019-02-08 11:39:25 +0800 |
commit | b94c2a12033362ec41ca5e5d65fb9d3e10da16e8 (patch) | |
tree | 90dc8e12f47b6225009b51d5b1c8198d16c6bc45 | |
parent | 0739a3e88b5f40e6edf0a707f36d7548d84d85c8 (diff) | |
download | rapidjson-b94c2a12033362ec41ca5e5d65fb9d3e10da16e8.tar.gz |
Adding swap() for GenericMember
-rw-r--r-- | example/sortkeys/sortkeys.cpp | 5 | ||||
-rw-r--r-- | 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<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 @@ template <typename Encoding, typename Allocator> 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); + } }; /////////////////////////////////////////////////////////////////////////////// |