I noticed that std::flat_set and std::flat_map container adaptors provide some noexcept member functions, in particular there are the followings:
[[nodiscard]] bool empty() const noexcept;
size_type size() const noexcept;
However, all the other container adaptors provide the same member functions as non-noexcept:
[[nodiscard]] bool empty() const;
size_type size() const;
Is there a reason for this difference?
Adding the noexcept specific to a function that is not guaranteed to be non-throwing can be dangerous. This problem occurs precisely with the std::stack, std::queue and std::priority_queue container adapters, which provide the empty() and size() member functions since C++98, and therefore did not force the underlying container's member functions to be non-throwing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With