📝 add more examples
This commit is contained in:
parent
7e8ee6f8b8
commit
25c3c18474
18
docs/examples/get_allocator.cpp
Normal file
18
docs/examples/get_allocator.cpp
Normal 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);
|
||||||
|
}
|
||||||
1
docs/examples/get_allocator.output
Normal file
1
docs/examples/get_allocator.output
Normal file
@ -0,0 +1 @@
|
|||||||
|
"Hello, world!"
|
||||||
@ -10,10 +10,22 @@ Returns the allocator associated with the container.
|
|||||||
|
|
||||||
associated allocator
|
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
|
## Version history
|
||||||
|
|
||||||
- Unknown.
|
- Added in version 1.0.0.
|
||||||
|
|
||||||
!!! note
|
|
||||||
|
|
||||||
This documentation page is a stub.
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user