[llvm] [NFC][ADT] Add range wrapper for std::mismatch (PR #104838)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 13:32:52 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/104838
>From ba7a49494fbb754fd092b2a97d88faf7de665f6d Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 19 Aug 2024 12:24:23 -0700
Subject: [PATCH] [NFC][ADT] Add range wrapper for std::maximal
---
llvm/include/llvm/ADT/STLExtras.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 249ac384bec41..b2df0cd650ad7 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -2002,6 +2002,20 @@ template <typename R, typename Compare> auto max_element(R &&Range, Compare C) {
return std::max_element(adl_begin(Range), adl_end(Range), C);
}
+/// Provide wrappers to std::mismatch which take ranges instead of having to
+/// pass begin/end explicitly.
+/// This function returns a pair of iterators for the first mismatching elements
+/// from `R1` and `R2`. As an example, if:
+///
+/// R1 = [0, 1, 4, 6], R2 = [0, 1, 5, 6]
+///
+/// this function will return a pair of iterators, first pointing to R1[2] and
+/// second pointing to R2[2].
+template <typename R1, typename R2> auto mismatch(R1 &&Range1, R2 &&Range2) {
+ return std::mismatch(adl_begin(Range1), adl_end(Range1), adl_begin(Range2),
+ adl_end(Range2));
+}
+
template <typename R>
void stable_sort(R &&Range) {
std::stable_sort(adl_begin(Range), adl_end(Range));
More information about the llvm-commits
mailing list