#include "json.hpp" #include #include #include #include #include class String : public std::string { public: String() : std::string() { s_instanceCount++; } String(const String& str) : std::string(str) { s_instanceCount++; } String(const String& str, size_type pos, size_type len = std::string::npos) : std::string(str, pos, len) { s_instanceCount++; } String(const char* s) : std::string(s) { s_instanceCount++; } String(const char* s, size_type n) : std::string(s, n) { s_instanceCount++; } String(const_iterator first, const_iterator last) : std::string(first, last) { s_instanceCount++; } String(size_type n, char c) : std::string(n, c) { s_instanceCount++; } String(String&& str) : std::string(std::move(str)) { s_instanceCount++; } ~String() { s_instanceCount--; } static int s_instanceCount; }; int String::s_instanceCount = 0; void* AllocatorAlloc(unsigned int _count, unsigned int _align) { return _aligned_malloc(_count, _align); } void AllocatorFree(void* _ptr) { _aligned_free(_ptr); } template struct Allocator { typedef std::remove_const_t value_type; typedef value_type* pointer; typedef value_type& reference; typedef const value_type* const_pointer; typedef const value_type& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; template struct rebind { typedef Allocator other; }; Allocator() throw() {} Allocator(const Allocator&) throw() {} template Allocator(const Allocator&) throw() {} ~Allocator() throw() {} pointer address(reference oRef) const { return &oRef; } const_pointer address(const_reference oRef) const { return &oRef; } pointer allocate(size_type iCount) { return (pointer)AllocatorAlloc(((unsigned int)iCount) * sizeof(T), alignof(T)); } pointer allocate(size_type iCount, const void*) { return allocate(iCount); } void deallocate(pointer pBuf, size_type) { AllocatorFree(pBuf); } size_type max_size() const throw() { size_type iCount = (size_type)(-1) / sizeof(T); return 0 < iCount ? iCount : 1; } void construct(pointer pT, const T& oT) { ::new ((void*)pT) T(oT); } void destroy(pointer pT) { pT->~T(); } private: }; using Json = ::nlohmann::basic_json; int main() { { Json json; json["test"] = Json::array_t{}; json["test"].push_back("Leak"); } std::cout << String::s_instanceCount << std::endl; // notice how s_instanceCount = 1 when Allocator is not std::allocator return 0; }