Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are deque's pop_front() and pop_back() not noexcept?

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?

like image 694
Benjamin Buch Avatar asked Nov 21 '18 11:11

Benjamin Buch


People also ask

What does Pop_front return in C++?

What the compiler tells you is rather straight forward: the pop_front() function does not returns the value of the front element. It simply removes it from the container. To access the element at front, you need to use the access function front() .

How to remove back element from queue in c++?

pop_back() function is used to pop or remove elements from a deque from the back. The value is removed from the deque from the end, and the container size is decreased by 1. If the deque is empty, it shows undefined behaviour.


Video Answer


1 Answers

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.

like image 157
Rémi Galan Alfonso Avatar answered Oct 20 '22 19:10

Rémi Galan Alfonso