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

The C ++ 14 standard defines find () member functions for 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 go wrong inside that would require throwing an exception or creating undefined behavior (besides not finding an element, in this case the function returns an end iterator, and in any case no exception is required)?

+6
source share
1 answer

find() based on the Compare() method of a map that can throw an exception (imagine the case of a complex key that might be wrong). Thus, we cannot be sure that find() will not throw an exception.

+4
source

All Articles