[PATCH] D146061: [ADT] Make llvm::is_contained call member `contains` when available
Jakub Kuderski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 13:36:16 PDT 2023
kuhar added a comment.
In D146061#4194439 <https://reviews.llvm.org/D146061#4194439>, @dblaikie wrote:
> This one is trickier for me - `llvm::is_contained` doesn't have a nearby standard equivalent ,so we can choose its behavior more flexibly. But `std::find(iter, iter, value)` exists in the standard library and there's value in `llvm::find(range, value)` being pretty close to the same/identical to the standard version - which doesn't optimize to member-find when available.
>
> I would be inclined not to include a member-find optimization in `llvm::find` for that reason.
>
> I'm undecided about whether that tips in favor of not having member-contains in `llvm::is_contained`.
Then I propose we frame it like this: `llvm::is_contained` is the (llvm-only) canonical/generic way to check if an element is in the range. We make it 'do the right thing' by default and use `.contains`, `.find`, and `std::find` when available, in this order of preference. This will make it work with C++17 containers that do not have `.contains`, llvm and C++20+ containers with `.contains`, and any other range via a linear scan. WDYT?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146061/new/
https://reviews.llvm.org/D146061
More information about the llvm-commits
mailing list