I'd like to force the use of explicit allocator template type parameters when using standard containers, including string.
Obviously I can do this by modifying the headers that come with the compilation system to remove the defaults for the allocator parameters. But this introduces a maintenance issue and also (for some compilation systems) might even require the use of custom-compiled runtimes.
What is the easiest way to do this within the language? Preferably, by #including a standard header (e.g., <string>
) and following it with some kind of code ... or maybe wrapping the #include of a standard header in a header of my own (and leaving the original <string>
out of the include search path).
(Motivating example: I want to implement region-based memory allocation throughout my server/service, and thus always want to use allocators that statefully refer to specific heaps. I can use stateful allocators with C++11 and later, and with some pre-C++11 compilation systems. I will provide a bunch of my own typedefs and alias templates to make things less painful for the programmer in this system. I want the restriction that the "default" allocator is never used to be enforced by the compilation system - not by a SCM submit rule. I don't have to worry about "malicious" programmers trying to defeat the restriction, I just don't want someone to make the easy mistake of not specifying an allocator each and every time.)
Aucun commentaire:
Enregistrer un commentaire