What's the rationale for the push_back method name in C++ std::vector? For instance, is there a stack-based origin (push being a common stack operation)? Was there a pre-existing library that used these terms for adding to a sequence?
Besides common terms other APIs use like append and add, insert_end would seem to be more internally self-consistent (though front and back do exist elsewhere).
As you mention, push and pop are common names for stack operations. The reason it's not just push and pop is so that it can be consistent with the other containers. std::vector only implements push_back and pop_back, but there is also push_front and pop_front in, for example, std::list. Having consistent names is useful when writing generic functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With