I've been using Howard Hinnant's stack allocator and it works like a charm, but some details of the implementation are a little unclear to me.
- Why are global operators
newanddeleteused? Theallocate()anddeallocate()member functions use::operator newand::operator deleterespectively. Similarly, the member functionconstruct()uses the global placement new. Why not allow for any user-defined global or class-specific overloads? - Why is alignment set to hard-coded 16 bytes instead of
std::alignment_of<T>? - Why do the constructors and
max_sizehave athrow()exception specification? Isn't this discouraged (see e.g. More Effective C++ Item 14.)? Is it really necessary to terminate and abort when an exception occurs in the allocator? Does this change with the new C++11noexceptkeyword? - The
construct()member function would be an ideal candidate for perfect forwarding (to the constructor that is being called). Is this the way to write C++11 conformant allocators? - What other changes are necessary to make the current code C++11 conformant?