C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sat, 23 Dec 2023 23:53:11 +0100
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_at_[hidden]> 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_at_[hidden]; CC:Giuseppe D‘Angelo <giuseppe.dangelo_at_[hidden]>; 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

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