mirror of
https://github.com/nlohmann/json.git
synced 2026-10-13 09:47:12 +00:00
deploy: 40a62947d3
This commit is contained in:
1 parent
79119509a9
commit
22fba27145
555 files changed
+17342
-1394
No files matched your search
@@ -25,13 +25,32 @@ Constant.
|
||||
The example shows how `get_allocator()` is used to created `json` values.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/get_allocator.cpp"
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
auto alloc = json::get_allocator();
|
||||
using traits_t = std::allocator_traits<decltype(alloc)>;
|
||||
|
||||
json* j = traits_t::allocate(alloc, 1);
|
||||
traits_t::construct(alloc, j, "Hello, world!");
|
||||
|
||||
std::cout << *j << std::endl;
|
||||
|
||||
traits_t::destroy(alloc, j);
|
||||
traits_t::deallocate(alloc, j, 1);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/get_allocator.output"
|
||||
"Hello, world!"
|
||||
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
Reference in new issue
Block a user