Commit daba1b6a authored by Mike Bogdanov's avatar Mike Bogdanov

fixed conformance with C++17, some members of allocator are depricated and...

fixed conformance with C++17, some members of allocator are depricated and should be used via allocator_traits
parent 0e3a0b73
......@@ -7944,12 +7944,15 @@ class basic_json
static T* create(Args&& ... args)
{
AllocatorType<T> alloc;
using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
auto deleter = [&](T * object)
{
alloc.deallocate(object, 1);
AllocatorTraits::deallocate(alloc, object, 1);
};
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
alloc.construct(object.get(), std::forward<Args>(args)...);
std::unique_ptr<T, decltype(deleter)> object(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);
assert(object != nullptr);
return object.release();
}
......@@ -8937,6 +8940,39 @@ class basic_json
~basic_json()
{
assert_invariant();
switch (m_type)
{
case value_t::object:
{
AllocatorType<object_t> alloc;
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.object);
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.object, 1);
break;
}
case value_t::array:
{
AllocatorType<array_t> alloc;
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.array);
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.array, 1);
break;
}
case value_t::string:
{
AllocatorType<string_t> alloc;
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
break;
}
default:
{
// all other types need no specific destructor
break;
}
}
m_value.destroy(m_type);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment