c++vector

Why there is no pop_front method in C++ std::vector?


Why there is no pop_front method in C++ std::vector?


Solution

  • Because a std::vector has no particular feature regarding inserting/removing elements at the front, unlike some other containers. The functionality provided by each container makes sense for that container.

    You probably should be using a std::deque, which is explicitly good at inserting/removing at the front and back.

    Check this diagram out.