MCPcopy Create free account
hub / github.com/boostorg/json / set1

Function set1

test/doc_quick_look.cpp:19–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17namespace json {
18
19static void set1() {
20
21//----------------------------------------------------------
22{
23// tag::doc_quick_look_1[]
24object obj; // construct an empty object
25obj[ "pi" ] = 3.141; // insert a double
26obj[ "happy" ] = true; // insert a bool
27obj[ "name" ] = "Boost"; // insert a string
28obj[ "nothing" ] = nullptr; // insert a null
29obj[ "answer" ].emplace_object()["everything"] = 42; // insert an object with 1 element
30obj[ "list" ] = { 1, 0, 2 }; // insert an array with 3 elements
31obj[ "object" ] = { {"currency", "USD"}, {"value", 42.99} }; // insert an object with 2 elements
32// end::doc_quick_look_1[]
33}
34//----------------------------------------------------------
35{
36// tag::doc_quick_look_2[]
37value jv = {
38 { "pi", 3.141 },
39 { "happy", true },
40 { "name", "Boost" },
41 { "nothing", nullptr },
42 { "answer", {
43 { "everything", 42 } } },
44 {"list", {1, 0, 2}},
45 {"object", {
46 { "currency", "USD" },
47 { "value", 42.99 }
48 } }
49 };
50// end::doc_quick_look_2[]
51}
52//----------------------------------------------------------
53{
54// tag::doc_quick_look_3[]
55array arr; // construct an empty array
56arr = { 1, 2, 3 }; // replace the contents with 3 elements
57value jv1( arr ); // this makes a copy of the array
58value jv2( std::move(arr) ); // this performs a move-construction
59
60assert( arr.empty() ); // moved-from arrays become empty
61arr = { nullptr, true, "boost" }; // fill in the array again
62// end::doc_quick_look_3[]
63}
64//----------------------------------------------------------
65{
66// tag::doc_quick_look_4[]
67{
68 unsigned char buf[ 4096 ]; // storage for our array
69 static_resource mr( buf ); // memory resource which uses buf
70 array arr( &mr ); // construct using the memory resource
71 arr = { 1, 2, 3 }; // all allocated memory comes from `buf`
72}
73// end::doc_quick_look_4[]
74}
75//----------------------------------------------------------
76{

Callers

nothing calls this directly

Calls 3

resizeMethod · 0.80
emptyMethod · 0.45
get_allocatorMethod · 0.45

Tested by

no test coverage detected