| 922 | /// @} |
| 923 | |
| 924 | private: |
| 925 | |
| 926 | /// helper for exception-safe object creation |
| 927 | template<typename T, typename... Args> |
| 928 | JSON_HEDLEY_RETURNS_NON_NULL |
| 929 | static T* create(Args&& ... args) |
| 930 | { |
| 931 | AllocatorType<T> alloc; |
| 932 | using AllocatorTraits = std::allocator_traits<AllocatorType<T>>; |
| 933 | |
| 934 | auto deleter = [&](T * obj) |
| 935 | { |
| 936 | AllocatorTraits::deallocate(alloc, obj, 1); |
| 937 | }; |
| 938 | std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter); |
| 939 | AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...); |
| 940 | JSON_ASSERT(obj != nullptr); |
| 941 | return obj.release(); |
| 942 | } |
| 943 | |
| 944 | //////////////////////// |
| 945 | // JSON value storage // |