#ifndef ALLOCATOR_GUIDE_EXAMPLE_OFFSET_POINTER_ALLOCATOR #define ALLOCATOR_GUIDE_EXAMPLE_OFFSET_POINTER_ALLOCATOR /* Example allocator that uses the fancy pointer OffPtr. This particular * allocator is stateless and does nothing useful beyond providing a use case * for OffPtr. */ #include #include "offptr.hpp" template struct Alloc { using value_type = T; using pointer = OffPtr; Alloc() = default; template Alloc(Alloc const &) noexcept { } pointer allocate(std::size_t n) { return pointer(static_cast(::operator new(n * sizeof(T)))); } void deallocate(pointer p, std::size_t) { ::operator delete(p.get()); } }; template bool operator==(Alloc const &, Alloc const &) { return true; } template bool operator!=(Alloc const &, Alloc const &) { return false; } #endif