Skip to content

Commit f595f8a

Browse files
committed
Update sortkeys.cpp
1 parent 1892013 commit f595f8a

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

example/sortkeys/sortkeys.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,52 @@
88
using namespace rapidjson;
99
using namespace std;
1010

11-
void printIt(const Value &doc)
12-
{
11+
static void printIt(const Value &doc) {
1312
char writeBuffer[65536];
1413
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
1514
PrettyWriter<FileWriteStream> writer(os);
1615
doc.Accept(writer);
17-
1816
cout << endl;
1917
}
2018

21-
struct NameComparator
22-
{
23-
bool
24-
operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
25-
const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const
19+
struct NameComparator {
20+
bool operator()(
21+
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
22+
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
2623
{
2724
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
2825
}
2926
};
3027

31-
int main()
32-
{
28+
int main() {
3329
Document d = Document(kObjectType);
3430
Document::AllocatorType &allocator = d.GetAllocator();
3531

3632
d.AddMember("zeta", Value().SetBool(false), allocator);
3733
d.AddMember("gama", Value().SetString("test string", allocator), allocator);
3834
d.AddMember("delta", Value().SetInt(123), allocator);
39-
40-
Value a(kArrayType);
41-
d.AddMember("alpha", a, allocator);
35+
d.AddMember("alpha", Value(kArrayType).Move(), allocator);
4236

4337
printIt(d);
4438

45-
/**
39+
/*
4640
{
4741
"zeta": false,
4842
"gama": "test string",
4943
"delta": 123,
5044
"alpha": []
5145
}
52-
**/
46+
*/
5347

5448
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
55-
5649
printIt(d);
57-
/**
50+
51+
/*
5852
{
5953
"alpha": [],
6054
"delta": 123,
6155
"gama": "test string",
6256
"zeta": false
6357
}
64-
**/
65-
return 0;
58+
*/
6659
}

0 commit comments

Comments
 (0)