In this example, we will create a stateless, equal allocator designed to allocator cache-aligned memory. The goal of this allocator is to show a C++17 allocator that can be leveraged to increase the efficiency of the objects a container is storing (for example, a linked list), as cache-thrashing is less likely to occur.
To start, we will define the allocator as follows:
template<typename T, std::size_t Alignment = 0x40>
class myallocator
{
public:
using value_type = T;
using pointer = T *;
using size_type = std::size_t;
using is_always_equal = std::true_type;
template<typename U> struct rebind {
using other = myallocator<U, Alignment>;
};
public:
myallocator()
{ }
template <typename U>
myallocator(const myallocator<U, Alignment> &other) noexcept
...