Does std::remove keep the removed elements around or could they be overwritten?

61 Views Asked by At
int main() {
    std::vector<bool> v(10, false);
    v[0] = true;
    v[1] = true;
    auto end_it = remove(v.begin(), v.end(), true);
    for (int i = 0; i < v.size(); ++i) cout << v[i] << endl;
}

From difference between erase and remove/remove_if algorithms?, my understanding is that all the elements in v that are true will be shifted to the end of v, but when I print the above it prints all false, so it appears my interpretation of the linked answer is not correct.

Is what happens from end_it to v.end() defined behavior?

0

There are 0 best solutions below