16

Is there any reason that std::deque's pop_front() and pop_back() are not noexcept in C++11 and higher or was that just forgotten?

Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51

1 Answers1

9

If I understood correctly, the standard doesn't specify noexcept on functions with a narrow contract (with a precondition which violation leads to UB). N3279 and more recently P0884 are talking about this and about how to decide whether a function should be noexcept or not (or conditionally).

This is the case for std::deque's pop_front and pop_back but also on front and back where there is no call to a destructor. Same for std::vector's pop_back, front and back for example.

  • 2
    This is correct. The idea was to allow implementations to throw an exception if they detected a contract violation. If these functions were marked as noexcept the program would call std::terminate. – Arnaud Nov 22 '18 at 16:16