1

The C++ iterator library contains the back_insert_iterator which is an output-iterator calling push_backon its container. I can use it together with containers like vector, dequeor listwhich makes the usage of algorithms like std::copyquite handy. Now I wanted to use a queue which does not have a function push_back but only a function push. I am wondering:

  1. Why is the member function called push and not push_back?
  2. If it is named push, why not provide a specialized back_insert_iteratorfor queue?
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Kilian
  • 533
  • 4
  • 11
  • Why the "language-lawyer" tag? – Robert Andrzejuk Mar 08 '19 at 22:41
  • @1201ProgramAlarm: On the one hand, this question is not about how to fix it; it's about why they are this way. So it's not really a duplicate of that question. On the other hand, such questions are of dubious merit, so I'm inclined to leave it closed. – Nicol Bolas Mar 08 '19 at 22:43
  • @RobertAndrzejuk because I am interested about this topic from a C++-standard point of view. If there is not a good reason why the function is called push and not push_back I would suggest to write a proposal to add the function push_back to the container-adapter. But I hope that there are good reasons and I want to know and understand them. – Kilian Mar 08 '19 at 22:47
  • A queue is always one direction. The queue pushes the elements on the back of the underlying container and pops them from the front. So actually push_back, do not make any meaning for queue. So obviously back_insert_iterator too. – Pavan Chandaka Mar 08 '19 at 22:50
  • 1
    @Kilian: "*because I am interested about this topic from a C++-standard point of view.*" The language-lawyer tag is for questions about what the specification says, not *why* the specification says it. The specification details what is C++; it doesn't go into issues of why C++ is the way it is. – Nicol Bolas Mar 08 '19 at 23:19

0 Answers0