Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the etymology of push_back in C++?

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).

like image 365
xan Avatar asked Mar 14 '12 00:03

xan


1 Answers

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.

like image 151
Alex Avatar answered Sep 18 '22 12:09

Alex