Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If an STL container lacks a method, it's a hint that 'here be dragons'. For example, random access of a std::list: it's possible, but you don't want the uninformed to be doing it without considering the consequences simply because it's easy to write.

What do you do about the memory allocated for the first element? That's a decision for the programmer to think about, not for the standard to enforce. A std::deque may deallocate.

Additionally, you can just do:

    std::stack<T, std::vector<T>>
to get pop.


You're arguing that there aren't STL methods for doing inefficient things.

But the parent took that as a given. Their comment translates as, "why doesn't the STL allow efficient removal at the front of a vector" (which would be possible in principle, e.g. python bytearray is similar but supports it). Part of the answer is that it would need an extra internal data member.

BTW the pop on std::stack refers to the back so doesn't help with pop_front (and vector already supports pop_back).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: