E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ mismatch

eve::algo::mismatch = function_with_traits<mismatch_>[find_if.get_traits()]
inlineconstexpr

#include <eve/module/algo/algo/mismatch.hpp>

Finds the point where two ranges are different (accepts anything that zips together as a range of 2 things). By default aligns and unrolls 4 times.

Alternative Header

#include <eve/algo.hpp>

Callable Signatures

namespace eve::algo
{
template <zipped_range_pair Rng>
auto mismatch(Rng&& rng) -> unalinged_t<decltype(rng.begin())>; // 1
template <zipped_range_pair Rng, typename P>
auto mismatch(Rng&& rng, P p) -> unalinged_t<decltype(rng.begin())>; // 2
template<typename R1, typename R2>
auto mismatch(R1&& r1, R2&& r2) requires zip_to_range<R1, R2> // 3
template<typename R1, typename R2, typename P>
auto mismatch(R1&& r1, R2&& r2, P p) requires zip_to_range<R1, R2> // 4
}
constexpr auto mismatch
a SIMD version of std::mismatch
Definition: mismatch.hpp:114
A relaxed_iterator on top of multiple relaxed_iterator. If all of the components are iterator they ha...
Definition: zip_iterator.hpp:294
  1. Compare both halves of zipped_range_pair for equality
  2. Compare both halves of zipped_range_pair for equivalence using predicate P
  3. Compare r1 and r2 that zip together to zip_range_pair for equality
  4. Compare r1 and r2 that zip together to zip_range_pair for equivalence using predicate P
Note
1. and 3. will convert to common type to do equality comparison if necessary to get the same for custom predicate, use [common_type] trait on your zip.
to better understand the zip interfaces, have a look at examples/algorithms/using_existing/memcmp_... or examples/algorithms/using_existing/case_insensitive....

Parameters

  • rng: zipped pair of 2 ranges to compare
  • 'r1,r2- two separate components thatzipto azipped_range_pair *p` - binary predicate for equivelence testing.

Return value

eve::views::zip_iterator to the place where the mismatch happend. (if not found, will point past the end of both halves).

Example

#include <eve/module/core.hpp>
#include <eve/module/algo.hpp>
#include <iostream>
#include <vector>
#include <tts/tts.hpp>
int main()
{
std::vector<int> v = {2,5,-9, 9, 3,-8,2,-5,7,-2,3};
std::vector<int> w = {2,5,-9, -9, -9,-8,2,-5,7,-2,3};
std::cout << " -> v = "
<< tts::as_string(v)
<< "\n";
std::cout << " -> w = "
<< tts::as_string(w)
<< "\n";
auto [vv, ww] = eve::algo::mismatch(v, w);
std::cout << " <- auto [vv, ww] = eve::algo::mismatch(v, ww);\n";
std::cout << " -> mismatch at " << eve::read(vv) << " != " << eve::read(ww) << std::endl;
// ignoring sign
auto [no_sign_vv, no_sign_ww] = eve::algo::mismatch(v, w, [](auto x, auto y) {
return x == y || x == -y;
});
std::cout << " <- auto [no_sign_vv, no_sign_ww] = eve::algo::mismatch(v, w, [](...){ });\n";
std::cout << " -> mismatch at " << eve::read(no_sign_vv) << " != " << eve::read(no_sign_ww) << std::endl;
}
constexpr auto read
Callable object reading single value from memory.
Definition: read.hpp:73