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

前端 未结 6 1822
醉话见心
醉话见心 2020-12-15 02:27

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

6条回答
  •  抹茶落季
    2020-12-15 03:10

    Because push_back and pop_back are special operations for a vector that require only O(1) computation. Any other push or pop takes O(n).

    This is not a "bug" or a "quirk", this is just a property of the vector container. If you need a fast pop_front consider changing to an other container.

提交回复
热议问题