#pragma once #include #include template struct fast_allocator { typedef Tp value_type; fast_allocator() = default; template fast_allocator(const fast_allocator&) {} Tp* allocate(std::size_t n); void deallocate(Tp* p, std::size_t n); }; template Tp* fast_allocator::allocate(std::size_t n) { // hopefully we're using jemalloc here! Tp* mem = static_cast(malloc(n * sizeof(Tp))); if (mem != nullptr) return mem; throw std::bad_alloc(); } template void fast_allocator::deallocate(Tp* p, std::size_t) { // hopefully we're using jemalloc here! free(p); } template bool operator==(const fast_allocator&, const fast_allocator&) { return true; } template bool operator!=(const fast_allocator& a, const fast_allocator& b) { return !(a == b); }