ranges::is_permutation

ranges::is_permutation (순열 동등 검사)

두 범위가 순서는 달라도 원소의 다중집합으로 같은지 검사하는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::is_permutation은 두 범위가 서로의 순열인지 검사해요.

namespace std::ranges {
template< std::forward_iterator I1, std::sentinel_for<I1> S1,
          std::forward_iterator I2, std::sentinel_for<I2> S2,
          class Pred = ranges::equal_to,
          class Proj1 = std::identity, class Proj2 = std::identity >
constexpr bool is_permutation( I1 first1, S1 last1, I2 first2, S2 last2,
                               Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 원소의 종류와 개수가 완전히 같으면 true.
  • proj1/proj2로 두 범위를 다르게 투영해 비교할 수도 있어요.
std::vector<int> a{1, 2, 3, 4, 5};
std::vector<int> b{5, 4, 3, 2, 1};
bool perm = std::ranges::is_permutation(a, b);   // true

순서는 무시하고 "같은 원소를 같은 개수로 들고 있는지"를 확인하는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference