fixed conformance with C++17, some members of allocator are depricated and should be used via allocator_traits

This commit is contained in:
Mike Bogdanov 2017-12-05 14:27:08 +03:00
parent 0e3a0b730b
commit daba1b6a0b

View file

@ -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);
}