Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception Requirements on Standard Containers

C++11 §23.2.1.10 specifies:

Unless otherwise specified all container types defined in this Clause meet the following additional requirements:

  • if an exception is thrown by an insert() or emplace() function while inserting a single element, that function has no effects.
  • no erase() , clear() , pop_back() or pop_front() function throws an exception.

Regarding the first bullet point, How does the container guarantee that? The constructor for T might have side-effects. Should it not be "has no effect on the container"

Regarding the second bullet point, This normally calls allocator::deallocate(T*,size_t) which is not noexcept. Why should eventual exceptions be masked away?

like image 768
sp2danny Avatar asked Aug 24 '15 20:08

sp2danny


1 Answers

Table 28 specifies one of the requirements of an allocator is that deallocate() "Does not throw exceptions". That is how the standard can make the assertion about erase(), clear(), pop_back() and pop_front()

like image 193
Michael Burr Avatar answered Nov 07 '22 20:11

Michael Burr