For one of my projects I need to frequently pop the first element in my vector. I can use the .erase() member function, and I have been advised to change my container to deque.
I am just thinking, naively, it would be great that I could add a member function pop_front(). For my case, this function will only do a few operations. First it adds 1 to the head iterator (if there's a private member of type iterator called "head") so that .begin() returns the new beginning iterator, and then subtract 1 from the size (if there's a private member of type unsigned called "size"), and then keep modifying other members that will be affected. So whenever I call .pop_front(), it will do only these a few operations, sounds efficient?
Is this something can be done or the idea is just going to result in big mess? If it's possible to do, so far the bad side of I can think of is that some boundary problems could happen when doing "vector in vector style", which in my project will never show up.
I noticed the .resize()'s complexity is linear on the number of elements inserted/erased if no reallocation happens. I am wondering why it's not constant? Why doesn't .resize() just reset the ending iterator(if there's a private member of type iterator named "end")?
Of course it's possible that I am all wrong about understanding how STL containers were implemented..
Thanks!