Suppose we are given std::vector<T> V
and an iterator p
to a position within the vector.
Q1: What is a good way to return a new vector w
for which the given iterator p
is std::end(w)?
I could create a new vector w
, move the elements from std::begin(v) to p
and assign p = std::end(w)
.
Q2: Is there a way to do what I want but keeping p
const
?
The origin of my question is the following: I have a vector for which I applied std::remove(std::begin(v),std::end(v), elem)
. This should put all the elements that are not equal to elem
and return an iterator to the end of that range. I would like to clip the vector there.