I'm a bit confused atm, I don't know when to use const T& or T& or T as a parameter.
Currently I'm doing:
void Resize(std::vector<T> &Vec, const size_t &NewLength) //Ahh edited the function as a result of Lucaci's answer.
{
Vec.resize(NewLength);
}
//But thinking of doing:
void Resize(std::vector<T> &Vec, size_t &NewLength)
{
Vec.resize(NewLength);
}
//And:
void Resize(std::vector<T> &Vec, size_t NewLength)
{
Vec.resize(NewLength);
}
//The reason I'm thinking like this is because I may have to pad the vector like so:
void Resize(const std::vector<T> Vec, const size_t &NewLength, const T& Padding)
{
Vec.resize(NewLength, Padding);
}
Now my question is: Which is the best to use? If I use const T&, will it create temporaries every single time? Inother words, will it create a copy of the padding every single time the function is called? Will it create a copy of the padding only once for the resize or will it do it NewLength amount of times or not at all?
Basically I want to know if const T& works the same as T&. I don't want to copy anything as I need the speed. Also what is the difference between const T* vs const T&?