T
Tino
I have a std::vector<int> which, after some initialization, has a
fixed number of elements...after initialization I must do the
following repeatedly: I remove an element which could be anywhere in
the vector, and add another element which will always be at the end,
ie.
vector<int> v;
int i, x;
.... initialization
v.erase( v.begin() + i );
v.push_back( x );
My question is whether there is a better way to do this...since I know
that there will always be a sequence of removing an element followed
by appending an element to the end, can I do it in a way which doesn't
use either erase or push_back? Or are most implementations such that
this shouldn't be a problem? Since this erase/push_back sequence will
happen many times, I would like to avoid any possible memory
management since the size of the vector will never really change.
Regards,
Tino
fixed number of elements...after initialization I must do the
following repeatedly: I remove an element which could be anywhere in
the vector, and add another element which will always be at the end,
ie.
vector<int> v;
int i, x;
.... initialization
v.erase( v.begin() + i );
v.push_back( x );
My question is whether there is a better way to do this...since I know
that there will always be a sequence of removing an element followed
by appending an element to the end, can I do it in a way which doesn't
use either erase or push_back? Or are most implementations such that
this shouldn't be a problem? Since this erase/push_back sequence will
happen many times, I would like to avoid any possible memory
management since the size of the vector will never really change.
Regards,
Tino