For containers within the standard library or also custom containers from the user?


AFAIU it is already allowed (by the standard for implementations) that std::ranges::contains is optimized to the data structure of the container (e.g. binary tree).


If you or the OP want to have guaranteed optimization, perhaps those guarantees could be demanded without ABI break?

-----Ursprüngliche Nachricht-----
Von: Giuseppe D‘Angelo via Std-Proposals <>
Gesendet: Sa 23.12.2023 23:21
Betreff: Re: [std-proposals] Addition of std::contains to Simplify Container Value Checks
Anlage: untitled
CC: Giuseppe D‘Angelo <>;
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

Std-Proposals mailing list