Skip to content
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

[FEA]: add thrust::mismatch overloads with last2 parameter #3601

Open
bernhardmgruber opened this issue Jan 30, 2025 · 1 comment
Open

[FEA]: add thrust::mismatch overloads with last2 parameter #3601

bernhardmgruber opened this issue Jan 30, 2025 · 1 comment
Labels
thrust For all items related to Thrust.

Comments

@bernhardmgruber
Copy link
Contributor

Thrust only implements the mismatch overloads taking an unbounded second range: InputIt1 first1, InputIt1 last1, InputIt2 first2. However, since C++14 there are also overloads where we can specify the end of the second range: InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2. We should provide these overloads. See also: https://en.cppreference.com/w/cpp/algorithm/mismatch.

@bernhardmgruber bernhardmgruber added the thrust For all items related to Thrust. label Jan 30, 2025
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 30, 2025
@NailaRais
Copy link

// Overload without a binary predicate for bounded second range

template <typename InputIt1, typename InputIt2>
__host__ __device__
std::pair<InputIt1, InputIt2>
mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
{
    while (first1 != last1 && first2 != last2 && *first1 == *first2) {
        ++first1;
        ++first2;
    }
    return std::make_pair(first1, first2);
}

// Overload with a binary predicate for bounded second range
template <typename InputIt1, typename InputIt2, typename BinaryPredicate>
__host__ __device__
std::pair<InputIt1, InputIt2>
mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate p)
{
    while (first1 != last1 && first2 != last2 && p(*first1, *first2)) {
        ++first1;
        ++first2;
    }
    return std::make_pair(first1, first2);
}

How about this?

Add mismatch overloads with bounded second range

This commit implements two new overloads for the mismatch algorithm,
allowing users to specify both the beginning and end of the second range.
These overloads work with and without a custom binary predicate.
This change brings the implementation in line with the C++14 standard,
and is consistent with the overloads provided by the standard library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
thrust For all items related to Thrust.
Projects
Status: Todo
Development

No branches or pull requests

2 participants