ranges::mismatch

ranges::mismatch (불일치 지점 — ranges)

두 범위가 달라지는 첫 지점을 찾는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::mismatch는 두 범위를 앞에서 비교해 처음으로 원소가 달라지는 위치를 반복자 쌍으로 반환해요.

namespace std::ranges {
template< std::input_iterator I1, std::sentinel_for<I1> S1,
          std::input_iterator I2, std::sentinel_for<I2> S2,
          class Pred = ranges::equal_to,
          class Proj1 = std::identity, class Proj2 = std::identity >
constexpr mismatch_result<I1, I2>
    mismatch( I1 first1, S1 last1, I2 first2, S2 last2,
              Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 반환 타입 mismatch_result{in1, in2}. 불일치 지점의 두 반복자.
  • proj1/proj2로 다르게 투영해 비교할 수도 있어요.
std::string a = "hello world";
std::string b = "hello zoo";
auto [it1, it2] = std::ranges::mismatch(a, b);
// 'w'와 'z'

두 시퀀스가 어디까지 같은지 찾는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference