Faster alternative to push_back
Hello,
I am trying to modify a loop within a loop to make it run faster. I ma doing this by replacing push_back with insert. However, insert does not seem to work for me as it is giving build errors.
for (int i =0; i < rows; i++)
{
vector<double> temp1;
temp1.insert(temp1.end(), signal.begin(), signal.end());
}
This does not seem to work. It's push_back which works is:
vector<double> temp1;
temp1.reserve(512);
for (int i =0; i < rows; i++)
{
for (int j=0;j < cols;j++)
{
temp1.push_back(signal[i][j]);
}
}
I believe the error is occurring because signal is of type vector < vector < double > > while temp1 is vector < double > And since signal is further being passed into another function, I would not want to change the type. Any suggestion would be appreciated.
This has nothing to do with OpenCV but is just a regular C++-Problem. You recognize your problem correctly, temp1 and signal have to have the same type if you want to use insert. One thing you could do is to insert each signal[i] into temp.