| 17 | namespace json { |
| 18 | |
| 19 | static void set1() { |
| 20 | |
| 21 | //---------------------------------------------------------- |
| 22 | { |
| 23 | // tag::doc_quick_look_1[] |
| 24 | object obj; // construct an empty object |
| 25 | obj[ "pi" ] = 3.141; // insert a double |
| 26 | obj[ "happy" ] = true; // insert a bool |
| 27 | obj[ "name" ] = "Boost"; // insert a string |
| 28 | obj[ "nothing" ] = nullptr; // insert a null |
| 29 | obj[ "answer" ].emplace_object()["everything"] = 42; // insert an object with 1 element |
| 30 | obj[ "list" ] = { 1, 0, 2 }; // insert an array with 3 elements |
| 31 | obj[ "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[] |
| 37 | value 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[] |
| 55 | array arr; // construct an empty array |
| 56 | arr = { 1, 2, 3 }; // replace the contents with 3 elements |
| 57 | value jv1( arr ); // this makes a copy of the array |
| 58 | value jv2( std::move(arr) ); // this performs a move-construction |
| 59 | |
| 60 | assert( arr.empty() ); // moved-from arrays become empty |
| 61 | arr = { 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 | { |
nothing calls this directly
no test coverage detected