Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why std::map find() is not declared as noexcept?

C++14 standard defines the find() member functions of std::map as follows:

iterator find(const key_type& x);
const_iterator find(const key_type& x) const;

Why are these functions not defined as noexcept? What could possibly go wrong inside, that would require to throw an exception or produce undefined behavior (other than not finding an element in which case the function returns an end iterator and no exception throwing would be required anyway)?

like image 811
PowerGamer Avatar asked Jan 06 '16 16:01

PowerGamer


1 Answers

find() are based on the Compare() method of the map, that could throw an exception (imagine the case of a complex key that could be incorrect). So, we can not be sure that find() won't raise an exception.

like image 160
88877 Avatar answered Nov 12 '22 09:11

88877