ranges::includes

ranges::includes (정렬 범위 포함 검사)

첫 정렬 범위가 두 번째 정렬 범위를 포함하는지 검사하는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::includes는 정렬된 [first1, last1)이 정렬된 [first2, last2)를 포함하는지 판정해요.

namespace std::ranges {
template< std::input_iterator I1, std::sentinel_for<I1> S1,
          std::input_iterator I2, std::sentinel_for<I2> S2,
          class Proj1 = std::identity, class Proj2 = std::identity,
          std::indirect_strict_weak_order<std::projected<I1, Proj1>,
                                          std::projected<I2, Proj2>> Comp = ranges::less >
constexpr bool includes( I1 first1, S1 last1, I2 first2, S2 last2,
                         Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 두 범위는 정렬되어 있어야 해요.
  • [first2, last2)의 모든 원소가 [first1, last1)에 있으면(개수까지), true.
std::vector<int> a{1, 2, 3, 4, 5};
std::vector<int> b{2, 4};
bool sub = std::ranges::includes(a, b);   // true

정렬된 시퀀스의 부분집합 포함을 확인할 때 쓰는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference