Skip to content

Commit ba7a494

Browse files
committed
[NFC][ADT] Add range wrapper for std::maximal
1 parent 87dd312 commit ba7a494

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,20 @@ template <typename R, typename Compare> auto max_element(R &&Range, Compare C) {
20022002
return std::max_element(adl_begin(Range), adl_end(Range), C);
20032003
}
20042004

2005+
/// Provide wrappers to std::mismatch which take ranges instead of having to
2006+
/// pass begin/end explicitly.
2007+
/// This function returns a pair of iterators for the first mismatching elements
2008+
/// from `R1` and `R2`. As an example, if:
2009+
///
2010+
/// R1 = [0, 1, 4, 6], R2 = [0, 1, 5, 6]
2011+
///
2012+
/// this function will return a pair of iterators, first pointing to R1[2] and
2013+
/// second pointing to R2[2].
2014+
template <typename R1, typename R2> auto mismatch(R1 &&Range1, R2 &&Range2) {
2015+
return std::mismatch(adl_begin(Range1), adl_end(Range1), adl_begin(Range2),
2016+
adl_end(Range2));
2017+
}
2018+
20052019
template <typename R>
20062020
void stable_sort(R &&Range) {
20072021
std::stable_sort(adl_begin(Range), adl_end(Range));

0 commit comments

Comments
 (0)