I want to make a template for an argument of a function.
The argument is a std::vector<type> with an allocator.
The default is to use the default memory allocator, but custom allocator can also be used.
The following code doesn't work. How to fix this?
template <typename T, typename T2=std::allocator<T>>
void pad_zero(std::vector<T,T2> vec, uint32_t n){
uint32_t i;
for (i = 0; i < n; i++){
vec.push_back(0);
}
}
Thanks.
=std::allocator<T>isn't necessary.veconly.>>is a problem in c++ standards before std c++11. It must be separated by space.std::fill_n, which you'd use like:fill_n(back_inserter(vec), n, 0);