Skip to content

[NFC][ADT] Add range wrapper for std::mismatch #104838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading