[clang-tools-extra] [llvm] [llvm][ADT] Add wrappers to `std::includes` (PR #143297)
Jakub Kuderski via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 9 08:01:23 PDT 2025
================
@@ -1881,6 +1881,19 @@ OutputIt move(R &&Range, OutputIt Out) {
return std::move(adl_begin(Range), adl_end(Range), Out);
}
+/// Provide wrappers to std::includes which take ranges instead of having to
+/// pass begin/end explicitly.
+template <typename R1, typename R2> bool includes(R1 &&Range1, R2 &&Range2) {
+ return std::includes(adl_begin(Range1), adl_end(Range1), adl_begin(Range2),
+ adl_end(Range2));
+}
+
+template <typename R1, typename R2, typename Compare>
+bool includes(R1 &&Range1, R2 &&Range2, Compare C) {
+ return std::includes(adl_begin(Range1), adl_end(Range1), adl_begin(Range2),
+ adl_end(Range2), C);
----------------
kuhar wrote:
For `forward` you'd have to pass `C` as `Compare &&` in the function signature. This way it will be moved if the caller passes an rvalue reference.
> I just have a question that why other places no need to forward C?
Most wrappers assume that predicates/comparators are cheap to copy (e.g., function pointer), but if they are not, each additional wrapper adds a layer of copying.
This suggestion was optional -- I don't think we strictly need it now, but it doesn't hurt to use `forward` now so that we don't have to update this code in the future.
https://github.com/llvm/llvm-project/pull/143297
More information about the cfe-commits
mailing list