#pragma once #include #include #include #include // Layout recovered from tungsten.exe.h. The allocator itself is stateless; // the PC port uses the process allocator until idLib's heap routing is active. struct testAlloc_t { void* ptr; int size; bool mapHeap; }; template class idSTLAllocator { public: using value_type = type; using pointer = type*; using const_pointer = const type*; using reference = type&; using const_reference = const type&; using size_type = std::size_t; using difference_type = std::ptrdiff_t; template struct rebind { using other = idSTLAllocator; }; idSTLAllocator() noexcept = default; template idSTLAllocator(const idSTLAllocator&) noexcept { } pointer allocate(const size_type count, const void* = nullptr) { if (count > max_size()) { throw std::bad_alloc(); } return static_cast(::operator new(count * sizeof(type))); } void deallocate(pointer address, size_type) noexcept { ::operator delete(address); } template void construct(objectType* address, argsType&&... args) { ::new (static_cast(address)) objectType( std::forward(args)...); } template void destroy(objectType* address) { address->~objectType(); } size_type max_size() const noexcept { return (std::numeric_limits::max)() / sizeof(type); } }; template inline bool operator==(const idSTLAllocator&, const idSTLAllocator&) noexcept { return true; } template inline bool operator!=(const idSTLAllocator&, const idSTLAllocator&) noexcept { return false; } #if defined(_WIN32) && !defined(_WIN64) static_assert(sizeof(testAlloc_t) == 12, "Recovered testAlloc_t ABI changed"); #endif