In the documentation of std::forward_list
, there are two member functions:
[[nodiscard]] bool empty() const noexcept;
size_type max_size() const noexcept;
What makes me surprised is:
Why does empty
has [[nodiscard]]
while max_size
doesn't?
The reason is two-part:
There is no way to confuse the query "what is the maximum size?" expressed as .maximum_size()
with anything else, while you could confuse the query "is it empty?" expressed as .empty()
with the command "empty it!", which got the name .clear()
.
[[nodiscard]]
is new, and has not been applied everywhere applicable in the standard library (to date). C++20 adds some places, but still isn't anywhere near comprehensive.