ranges::set_symmetric_difference

ranges::set_symmetric_difference (대칭 차집합 — ranges)

두 정렬 범위 중 정확히 한쪽에만 있는 원소를 출력하는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::set_symmetric_difference[first1, last1)[first2, last2)에 각각만 있는 원소(공통이 아닌 것)를 result에 복사해요.

namespace std::ranges {
template< std::input_iterator I1, std::sentinel_for<I1> S1,
          std::input_iterator I2, std::sentinel_for<I2> S2,
          std::weakly_incrementable O, class Comp = ranges::less,
          class Proj1 = std::identity, class Proj2 = std::identity >
requires std::mergeable<I1, I2, O, Comp, Proj1, Proj2>
constexpr set_symmetric_difference_result<I1, I2, O>
    set_symmetric_difference( I1 first1, S1 last1, I2 first2, S2 last2,
                              O result, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 반환 타입 set_symmetric_difference_result{in1, in2, out}.
  • 두 범위는 정렬되어 있어야 해요.
std::vector<int> a{1, 2, 3, 4, 5};
std::vector<int> b{2, 4, 6};
std::vector<int> out;
std::ranges::set_symmetric_difference(a, b, std::back_inserter(out));
// out == {1,3,5,6}

집합 이론의 "대칭 차집합"을 정렬된 시퀀스로 구하는 함수예요.

더 알아보기 (Learn more)

cppreference