What is the etymology of push_back in C ++?

What is the rationale for the name of the push_back method in C ++ std::vector ? For example, does the beginning of the stack exist ( push is the general operation of the stack)? Was there a pre-existing library that used these terms to add to the sequence?

Besides common terms, other APIs such as append and add , insert_end seem more internally self-consistent (although front and back exist elsewhere).

+4
source share
2 answers

As you noted, push and pop are common names for stack operations. The reason for this, not just push and pop is that it can be compatible with other containers. std::vector only implements push_back and pop_back , but there is, for example, push_front and pop_front , for example, std::list . Having consistent names is useful when writing common functions.

+9
source

I would suggest that it is because of these methods that make it easy to use std::vector as a stack --- if all you do is push_front(foo) and pop_front() (or the back equivalent), you have a stack .

0
source

Source: https://habr.com/ru/post/1401279/


All Articles