C++ Logo


Advanced search

Re: [std-proposals] Addition of std::contains to Simplify Container Value Checks

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sat, 23 Dec 2023 23:21:09 +0100
Il 23/12/23 22:10, Sebastian Wittmeier via Std-Proposals ha scritto:
> std::ranges::contains(range, value)
> does exactly that:
> - works over different container types
> - provides a standardized way for checking for the presence of a value
> So please state the advantages or differences of your proposal compared
> to it.

For starters, I'd like that if the container offers a `contains` method
on its own (e.g. on std::set), then `std::whatever::contains` uses
*that* one before falling back on linear search via std::(ranges::)find
(not dissimilar to Python's protocol for `in`).

My 2 c,
Giuseppe D'Angelo

Received on 2023-12-23 22:21:13