Adding swap() for GenericMember

This commit is contained in:
Milo Yip 2019-02-08 11:39:25 +08:00
parent 0739a3e88b
commit b94c2a1203
2 changed files with 7 additions and 4 deletions

View File

@ -17,10 +17,7 @@ static void printIt(const Value &doc) {
} }
struct NameComparator { struct NameComparator {
bool operator()( bool operator()(const Value::Member &lhs, const Value::Member &rhs) const {
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
{
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
} }
}; };

View File

@ -66,6 +66,12 @@ template <typename Encoding, typename Allocator>
struct GenericMember { struct GenericMember {
GenericValue<Encoding, Allocator> name; //!< name of member (must be a string) GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
GenericValue<Encoding, Allocator> value; //!< value of member. 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);
}
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////