| 19673 | /// @} |
| 19674 | |
| 19675 | private: |
| 19676 | |
| 19677 | /// helper for exception-safe object creation |
| 19678 | template<typename T, typename... Args> |
| 19679 | JSON_HEDLEY_RETURNS_NON_NULL |
| 19680 | static T* create(Args&& ... args) |
| 19681 | { |
| 19682 | AllocatorType<T> alloc; |
| 19683 | using AllocatorTraits = std::allocator_traits<AllocatorType<T>>; |
| 19684 | |
| 19685 | auto deleter = [&](T * obj) |
| 19686 | { |
| 19687 | AllocatorTraits::deallocate(alloc, obj, 1); |
| 19688 | }; |
| 19689 | std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter); |
| 19690 | AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...); |
| 19691 | JSON_ASSERT(obj != nullptr); |
| 19692 | return obj.release(); |
| 19693 | } |
| 19694 | |
| 19695 | //////////////////////// |
| 19696 | // JSON value storage // |