MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / using_polymorphic_allocator

Function using_polymorphic_allocator

examples/src/json_parse_examples.cpp:118–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117// since 0.171.0
118void using_polymorphic_allocator()
119{
120 using pmr_json = pmr::json;
121
122 char buffer[1024] = {}; // a small buffer on the stack
123 std::pmr::monotonic_buffer_resource pool{std::data(buffer), std::size(buffer)};
124 std::pmr::polymorphic_allocator<char> alloc(&pool);
125
126 std::string json_text = R"(
127 {
128 "street_number" : "100",
129 "street_name" : "Queen St W",
130 "city" : "Toronto",
131 "country" : "Canada"
132 }
133 )";
134
135
136 try
137 {
138 auto doc = pmr_json::parse(make_alloc_set(alloc), json_text, json_options{});
139 std::cout << pretty_print(doc) << "\n\n";
140 }
141 catch (const std::exception& ex)
142 {
143 std::cerr << ex.what() << '\n';
144 }
145}
146
147#endif
148

Callers 1

mainFunction · 0.85

Calls 5

sizeFunction · 0.85
parseFunction · 0.85
make_alloc_setFunction · 0.85
pretty_printFunction · 0.85
whatMethod · 0.45

Tested by

no test coverage detected