📝 add more examples

This commit is contained in:
Niels Lohmann 2022-05-10 19:41:37 +02:00
parent 7e8ee6f8b8
commit 25c3c18474
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 36 additions and 5 deletions

View File

@ -0,0 +1,18 @@
#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);
}

View File

@ -0,0 +1 @@
"Hello, world!"

View File

@ -10,10 +10,22 @@ Returns the allocator associated with the container.
associated allocator
## Examples
??? example
The example shows how `get_allocator()` is used to created `json` values.
```cpp
--8<-- "examples/get_allocator.cpp"
```
Output:
```json
--8<-- "examples/get_allocator.output"
```
## Version history
- Unknown.
!!! note
This documentation page is a stub.
- Added in version 1.0.0.