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 <std-proposals@lists.isocpp.org>
Gesendet: Sa 23.12.2023 23:21
Betreff: Re: [std-proposals] Addition of std::contains to Simplify Container Value Checks
Anlage: untitled
An: std-proposals@lists.isocpp.org;
CC: Giuseppe D‘Angelo <giuseppe.dangelo@kdab.com>;
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
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals