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?
Asked
Active
Viewed 1,092 times
16

Benjamin Buch
- 4,752
- 7
- 28
- 51
-
How could they be? – molbdnilo Nov 21 '18 at 12:01
1 Answers
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.

Rémi Galan Alfonso
- 106
- 3
-
2This 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