|
|
|
|
|
by acqq
4080 days ago
|
|
I also remember Bloomberg submitted in 2005 some very nice template library changes that avoid some very real pain points of STL: www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1850.pdf "Using an existing implementation of the
C++ standard library as a base, we made backward-compatible modifications to
enable such per-instance allocators." I still don't know how I'd achieve per-instance allocator in modern "part-of-standard C++ STL." Is it possible? If yes, how? Does anybody know? |
|
Well, there are two things you can do.
1. (Accepted in C++11) Allow stateful allocators. This is especially useful for things like pool allocators. Your container would keep a pointer to its allocator and perform allocator operations through it.
2. (Proposed but not accepted yet) Allow polymorphic allocators. This would allow different data structures to use different allocators but still have the same type. Basically it would look like 1 above, but instead of keeping an allocator pointer, you would keep a pointer to an allocator interface and perform allocator operations through virtual method calls.