From 25c3c1847421b5f6b3e8112ed2e8e8d10f3dbc8c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 10 May 2022 19:41:37 +0200 Subject: [PATCH] :memo: add more examples --- docs/examples/get_allocator.cpp | 18 +++++++++++++++ docs/examples/get_allocator.output | 1 + .../docs/api/basic_json/get_allocator.md | 22 ++++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 docs/examples/get_allocator.cpp create mode 100644 docs/examples/get_allocator.output diff --git a/docs/examples/get_allocator.cpp b/docs/examples/get_allocator.cpp new file mode 100644 index 000000000..4014ec3d9 --- /dev/null +++ b/docs/examples/get_allocator.cpp @@ -0,0 +1,18 @@ +#include +#include + +using json = nlohmann::json; + +int main() +{ + auto alloc = json::get_allocator(); + using traits_t = std::allocator_traits; + + 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); +} diff --git a/docs/examples/get_allocator.output b/docs/examples/get_allocator.output new file mode 100644 index 000000000..8effb3e8c --- /dev/null +++ b/docs/examples/get_allocator.output @@ -0,0 +1 @@ +"Hello, world!" diff --git a/docs/mkdocs/docs/api/basic_json/get_allocator.md b/docs/mkdocs/docs/api/basic_json/get_allocator.md index 1b7700c77..07a4d8456 100644 --- a/docs/mkdocs/docs/api/basic_json/get_allocator.md +++ b/docs/mkdocs/docs/api/basic_json/get_allocator.md @@ -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.