C++ standard library containers such as std::vector
accept an optional template parameter that lets you specify an alternate allocator. The examples I can find show this happening at each object creation via the syntax:
std::vector<T,custom::custom_allocator<T> >
Is there a way to globally set custom::custom_allocator<T>
such that I don’t need to include it in the template arguments every time? Preference would be for solutions that do not require wrapping the stl in custom code, or using processor text substitution.
11
If you use std::pmr::vector
, then you can pass in whatever allocator in the constructors, and not have to make any further changes to code that references but does not create new vectors. (pmr
stands for polymorphic)
Alternatively, use template<class T> using myvector = std::vector<T, custom::custom_allocator<T>>;