C++ allocators define a template class that allocates memory for a specific type T and are defined by the allocator concept definition. There are two different types of allocators:
- Allocators that are equal
- Allocators that are unequal
An allocator that is equal is an allocator that can allocate memory from one allocator and deallocate memory from another, for example:
myallocator<myclass> myalloc1;
myallocator<myclass> myalloc2;
auto ptr = myalloc1.allocate(1);
myalloc2.deallocate(ptr, 1);
As shown in the preceding example, we create two instances of myallocator{}. We allocate memory from one of the allocators and then deallocate memory from the other allocator. For this to be valid, the allocators must be equal:
myalloc1 == myalloc2; // true
If this does not hold true, the allocators are considered unequal, which greatly complicates how...