#pragma once namespace verus { //! Custom allocator for the Standard Template Library. Will try to use the allocator provided by Utils. template class AllocatorAwareSTL { void operator=(const AllocatorAwareSTL&); public: typedef T value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; AllocatorAwareSTL() {} AllocatorAwareSTL(const AllocatorAwareSTL&) {} ~AllocatorAwareSTL() {} template AllocatorAwareSTL(const AllocatorAwareSTL<_Other>& other) {} template struct rebind { typedef AllocatorAwareSTL other; }; pointer address(reference r) const { return &r; } const_pointer address(const_reference r) const { return &r; } pointer allocate(size_type n) { pointer p = static_cast(AllocatorAware::UtilsMalloc(n * sizeof(value_type))); if (p) { return p; } else { p = static_cast(malloc(n * sizeof(value_type))); char txt[80]; sprintf_s(txt, "allocate(), malloc() 0x%p", p); VERUS_LOG_DEBUG(txt); return p; } } void deallocate(pointer p, size_type) { if (!AllocatorAware::UtilsFree(p)) { char txt[80]; sprintf_s(txt, "deallocate(), free() 0x%p", p); VERUS_LOG_DEBUG(txt); free(p); } } void construct(pointer p, const value_type& val) { new(p)value_type(val); } void destroy(pointer p) { p->~value_type(); } size_type max_size() const { return ULONG_MAX / sizeof(value_type); } }; //! This function will compare two allocators. template bool operator==(const AllocatorAwareSTL& l, const AllocatorAwareSTL& r) { return true; } //! This function will compare two allocators. template bool operator!=(const AllocatorAwareSTL& l, const AllocatorAwareSTL& r) { return !(l == r); } } namespace verus { template using Vector = std::vector >; template using List = std::list >; template using Set = std::set , AllocatorAwareSTL>; template using MultiSet = std::multiset , AllocatorAwareSTL>; template using HashSet = std::unordered_set , std::equal_to, AllocatorAwareSTL>; template using Map = std::map , AllocatorAwareSTL>; template using MultiMap = std::multimap , AllocatorAwareSTL>; template using HashMap = std::unordered_map , std::equal_to, AllocatorAwareSTL>; }