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

Function usingInitLists

test/snippets.cpp:477–633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

475//----------------------------------------------------------
476
477void
478usingInitLists()
479{
480 {
481 // tag::snippet_init_list_1[]
482
483 value jv = {
484 { "name", "John Doe" },
485 { "active", true },
486 { "associated-accounts", nullptr },
487 { "total-balance", 330.00 },
488 { "account-balances", { 84, 120, 126 } } };
489
490 // end::snippet_init_list_1[]
491 }
492
493 {
494 // tag::snippet_init_list_2[]
495
496 value jv = { true, 2, "hello", nullptr };
497
498 assert( jv.is_array() );
499
500 assert( jv.as_array().size() == 4 );
501
502 assert( serialize(jv) == R"([true,2,"hello",null])" );
503
504 // end::snippet_init_list_2[]
505 }
506
507 {
508 // tag::snippet_init_list_3[]
509
510 value jv = { true, 2, "hello", { "bye", nullptr, false } };
511
512 assert( jv.is_array() );
513
514 assert( jv.as_array().back().is_array() );
515
516 assert( serialize(jv) == R"([true,2,"hello",["bye",null,false]])" );
517
518 // end::snippet_init_list_3[]
519 }
520
521 {
522 // tag::snippet_init_list_4[]
523
524 // Should this be an array or an object?
525 value jv = { { "hello", 42 }, { "world", 43 } };
526
527 // end::snippet_init_list_4[]
528 }
529
530 {
531 // tag::snippet_init_list_5[]
532
533 value jv1 = { { "hello", 42 }, { "world", 43 } };
534

Callers 1

runMethod · 0.85

Calls 5

serializeFunction · 0.85
is_arrayMethod · 0.80
is_objectMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected