C++ Logo

std-discussion

Advanced search

Re: The attribute nodiscard for the member function contains of associative containers.

From: Bo Persson <bo_at_[hidden]>
Date: Mon, 10 Aug 2020 12:19:08 +0200
On 2020-08-10 at 11:22, Vladimir Grigoriev via Std-Discussion wrote:
> The member function empty of associative containers has the attribute
> nodiscard. It seems that the new member function contains should also
> have the attribute, should not it?

Maybe. Or maybe not.

The nodiscard on empty() is to help people that intended to call
clear(). Had the name been is_empty() this would have been less of a
problem.

So what is the risk of people accidentally calling contains() when they
intended insert()? Pretty small, IMO.



     Bo Persson

Received on 2020-08-10 05:22:41