json/docs/examples/get_allocator.cpp

19 lines
401 B
C++
Raw Normal View History

2022-05-10 20:41:37 +03:00
#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)>;
2022-05-10 22:07:50 +03:00
json* j = traits_t::allocate(alloc, 1);
2022-05-10 20:41:37 +03:00
traits_t::construct(alloc, j, "Hello, world!");
std::cout << *j << std::endl;
traits_t::destroy(alloc, j);
traits_t::deallocate(alloc, j, 1);
}