@@ -29,6 +29,42 @@ inline thread_local PMR_NS::memory_resource* tl_mr = nullptr;
2929
3030void InitJSONTLHeap (PMR_NS::memory_resource* mr);
3131
32+ template <typename T> class JSONConsAllocator {
33+ public:
34+ using value_type = T;
35+ using size_type = std::size_t ;
36+ using difference_type = std::ptrdiff_t ;
37+ using is_always_equal = std::true_type;
38+
39+ template <typename U> JSONConsAllocator (const JSONConsAllocator<U>&) noexcept {
40+ }
41+
42+ JSONConsAllocator () noexcept = default ;
43+
44+ static value_type* allocate (size_type n) {
45+ void * ptr = detail::tl_mr->allocate (n * sizeof (value_type), alignof (value_type));
46+ return static_cast <value_type*>(ptr);
47+ }
48+
49+ static void deallocate (value_type* ptr, size_type n) noexcept {
50+ detail::tl_mr->deallocate (ptr, n * sizeof (value_type), alignof (value_type));
51+ }
52+
53+ static PMR_NS::memory_resource* resource () {
54+ return detail::tl_mr;
55+ }
56+ };
57+
58+ template <typename T, typename U>
59+ bool operator ==(const JSONConsAllocator<T>&, const JSONConsAllocator<U>&) noexcept {
60+ return true ;
61+ }
62+
63+ template <typename T, typename U>
64+ bool operator !=(const JSONConsAllocator<T>&, const JSONConsAllocator<U>&) noexcept {
65+ return false ;
66+ }
67+
3268using JsonType = jsoncons::pmr::json;
3369
3470// Build a json object from string. If the string is not legal json, will return nullopt
0 commit comments