[llvm] 8a677c1 - [NFC][ADT] Add range wrapper for std::mismatch (#104838)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 14:09:42 PDT 2024
Author: Rahul Joshi
Date: 2024-08-19T14:09:38-07:00
New Revision: 8a677c194072dc19ef680bebba9aa7eafb05b373
URL: https://github.com/llvm/llvm-project/commit/8a677c194072dc19ef680bebba9aa7eafb05b373
DIFF: https://github.com/llvm/llvm-project/commit/8a677c194072dc19ef680bebba9aa7eafb05b373.diff
LOG: [NFC][ADT] Add range wrapper for std::mismatch (#104838)
Added:
Modified:
llvm/include/llvm/ADT/STLExtras.h
Removed:
################################################################################
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