Skip to content

Commit b94c2a1

Browse files
committed
Adding swap() for GenericMember
1 parent 0739a3e commit b94c2a1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

example/sortkeys/sortkeys.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ static void printIt(const Value &doc) {
1717
}
1818

1919
struct NameComparator {
20-
bool operator()(
21-
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
22-
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
23-
{
20+
bool operator()(const Value::Member &lhs, const Value::Member &rhs) const {
2421
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
2522
}
2623
};

include/rapidjson/document.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ template <typename Encoding, typename Allocator>
6666
struct GenericMember {
6767
GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
6868
GenericValue<Encoding, Allocator> value; //!< value of member.
69+
70+
// swap() for std::sort() and other potential use in STL.
71+
friend inline void swap(GenericMember& a, GenericMember& b) RAPIDJSON_NOEXCEPT {
72+
a.name.Swap(b.name);
73+
a.value.Swap(b.value);
74+
}
6975
};
7076

7177
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)