diff options
author | Milo Yip <miloyip@gmail.com> | 2019-02-06 14:59:09 +0300 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2019-02-06 14:59:09 +0300 |
commit | f595f8a6a596d204423a380dfb145e593b647c07 (patch) | |
tree | c9c89f71cfb894f399ed3c35ad199c2e1ffe740c /example | |
parent | 1892013216a843029f3c8e39ccc9a7c8029891e8 (diff) |
Update sortkeys.cpp
Diffstat (limited to 'example')
-rw-r--r-- | example/sortkeys/sortkeys.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/example/sortkeys/sortkeys.cpp b/example/sortkeys/sortkeys.cpp index 85e08074..fe601185 100644 --- a/example/sortkeys/sortkeys.cpp +++ b/example/sortkeys/sortkeys.cpp @@ -8,59 +8,52 @@ using namespace rapidjson; using namespace std; -void printIt(const Value &doc) -{ +static void printIt(const Value &doc) { char writeBuffer[65536]; FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); PrettyWriter<FileWriteStream> writer(os); doc.Accept(writer); - cout << endl; } -struct NameComparator -{ - bool - operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs, - const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const +struct NameComparator { + bool operator()( + const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs, + const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const { return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); } }; -int main() -{ +int main() { Document d = Document(kObjectType); Document::AllocatorType &allocator = d.GetAllocator(); d.AddMember("zeta", Value().SetBool(false), allocator); d.AddMember("gama", Value().SetString("test string", allocator), allocator); d.AddMember("delta", Value().SetInt(123), allocator); - - Value a(kArrayType); - d.AddMember("alpha", a, allocator); + d.AddMember("alpha", Value(kArrayType).Move(), allocator); printIt(d); - /** +/* { "zeta": false, "gama": "test string", "delta": 123, "alpha": [] } -**/ +*/ std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator()); - printIt(d); - /** + +/* { "alpha": [], "delta": 123, "gama": "test string", "zeta": false } -**/ - return 0; +*/ } |