Fast way to implement pop_front to a std::vector

前端 未结 4 739
遇见更好的自我
遇见更好的自我 2021-02-01 17:25

I\'m using some classes and several utility methods that use std:: vector.

Now I need to use each frame a pop_front - push_back method on one of those classes (but they

4条回答
  •  死守一世寂寞
    2021-02-01 17:37

    Since pop_front() only erases the first element, the direct implementation is this:

    template 
    void pop_front(V & v)
    {
        assert(!v.empty());
        v.erase(v.begin());
    }
    

    Don't worry about speed for now. If you want to go back and optimize code, ask for dedicated project time.

提交回复
热议问题