Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
f595f8a6
Commit
f595f8a6
authored
6 years ago
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update sortkeys.cpp
parent
18920132
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
19 deletions
+12
-19
sortkeys.cpp
example/sortkeys/sortkeys.cpp
+12
-19
No files found.
example/sortkeys/sortkeys.cpp
View file @
f595f8a6
...
...
@@ -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
;
*/
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment