| 116 | |
| 117 | // since 0.171.0 |
| 118 | void 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 |
no test coverage detected