xref: /third_party/json/docs/examples/get_allocator.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ciusing json = nlohmann::json;
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ciint main()
7c5f01b2fSopenharmony_ci{
8c5f01b2fSopenharmony_ci    auto alloc = json::get_allocator();
9c5f01b2fSopenharmony_ci    using traits_t = std::allocator_traits<decltype(alloc)>;
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci    json* j = traits_t::allocate(alloc, 1);
12c5f01b2fSopenharmony_ci    traits_t::construct(alloc, j, "Hello, world!");
13c5f01b2fSopenharmony_ci
14c5f01b2fSopenharmony_ci    std::cout << *j << std::endl;
15c5f01b2fSopenharmony_ci
16c5f01b2fSopenharmony_ci    traits_t::destroy(alloc, j);
17c5f01b2fSopenharmony_ci    traits_t::deallocate(alloc, j, 1);
18c5f01b2fSopenharmony_ci}
19

Indexes created Thu Nov 07 10:32:03 CST 2024