Use pop_back_val() instead of both back() and pop_back().