I\'m trying to get a single element from a vector and push it to the back of the vector then remove it so I won\'t have an empty section in memory. The erase-remove idiom ca
If you don't care about maintaining the ordering of the elements in the vector, you can avoid the copy of the "tail" of remaining elements on erase:
auto it = std::find(v.begin(), v.end(), 3); if (it != v.end()) { std::iter_swap(it, v.end() - 1); v.erase(v.end() - 1); }