algorithm_is_partitioned
algorithm_is_partitioned (파티셔닝 검사)
std::is_partitioned는 소스 범위의 요소들이 술어 p를 기준으로 파티셔닝되어 있는지 검사해요. 즉 p를 만족하는 요소들이 그렇지 않은 요소들보다 먼저 오는지 확인해요.
출처: cppreference
본문
std::is_partitioned는 소스 범위 [first, last)의 요소 e가 표현식 bool(p(e))에 대해 파티셔닝되어 있는지 검사해요: p를 만족하는 모든 요소가 그렇지 않은 모든 요소보다 앞에 와야 해요. <algorithm> 헤더에 정의되어 있어요.
template< class InputIt, class UnaryPred >
bool is_partitioned( InputIt first, InputIt last, UnaryPred p );
병렬 실행 정책을 받는 오버로드도 있어요.
반환값 (Return value)
범위가 파티셔닝되어 있으면 true, 아니면 false예요. 빈 범위와 단일 요소 범위는 항상 파티셔닝되어 있다고 간주돼요.
복잡도 (Complexity)
N을 std::distance(first, last)라고 하면 최대 N번의 p 적용이 필요해요 (파티션 지점을 찾으면 끝나요).
예제 (Example)
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v{1, 2, 3, 4, 5, 6};
auto is_even = [](int x) { return x % 2 == 0; };
std::cout << std::boolalpha << std::is_partitioned(v.begin(), v.end(), is_even) << '\n';
auto it = std::partition(v.begin(), v.end(), is_even);
std::cout << std::boolalpha << std::is_partitioned(v.begin(), v.end(), is_even) << '\n';
}