std:: is_partitioned
|
헤더 파일에 정의됨
<algorithm>
|
||
|
template
<
class
InputIt,
class
UnaryPred
>
bool is_partitioned ( InputIt first, InputIt last, UnaryPred p ) ; |
(1) |
(C++11부터)
(C++20부터 constexpr) |
|
template
<
class
ExecutionPolicy,
class
ForwardIt,
class
UnaryPred
>
bool
is_partitioned
(
ExecutionPolicy
&&
policy,
|
(2) | (C++17부터) |
[
first
,
last
)
범위가 분할되었는지 확인합니다:
p
를 만족하는 모든 요소들이 만족하지 않는 모든 요소들 앞에 나타납니다.
|
std:: is_execution_policy_v < std:: decay_t < ExecutionPolicy >> 가 true 인 경우. |
(C++20 이전) |
|
std:: is_execution_policy_v < std:: remove_cvref_t < ExecutionPolicy >> 가 true 인 경우. |
(C++20 이후) |
목차 |
매개변수
| first, last | - | 검사할 요소들의 범위 를 정의하는 반복자 쌍 |
| policy | - | 사용할 실행 정책 |
| p | - |
범위의 시작 부분에서 찾을 것으로 예상되는 요소에 대해
true
를 반환하는 단항 predicate
표현식
p
(
v
)
는
|
| 타입 요구사항 | ||
-
InputIt
는
LegacyInputIterator
요구사항을 충족해야 합니다.
|
||
-
ForwardIt
는
LegacyForwardIterator
요구사항을 충족해야 하며, 그 값 타입은
UnaryPred
의 매개변수 타입으로 변환 가능해야 합니다.
|
||
-
UnaryPred
는
Predicate
요구사항을 충족해야 합니다.
|
||
반환값
true
를 반환합니다 - 만약
e
로 표현되는 요소들이 범위
[
first
,
last
)
내에서 표현식
p
(
e
)
에 대해
분할(partitioned)
되어 있다면.
false
를 반환합니다 - 그렇지 않은 경우.
복잡도
최대 std:: distance ( first, last ) 번의 p 적용.
예외
ExecutionPolicy
라는 템플릿 매개변수를 사용하는 오버로드는 다음과 같이 오류를 보고합니다:
-
알고리즘의 일부로 호출된 함수 실행 중 예외가 발생하고
ExecutionPolicy가 표준 정책 중 하나인 경우, std::terminate 가 호출됩니다. 다른ExecutionPolicy의 경우 동작은 구현에 따라 정의됩니다. - 알고리즘이 메모리 할당에 실패할 경우, std::bad_alloc 이 throw됩니다.
가능한 구현
template<class InputIt, class UnaryPred> bool is_partitioned(InputIt first, InputIt last, UnaryPred p) { for (; first != last; ++first) if (!p(*first)) break; for (; first != last; ++first) if (p(*first)) return false; return true; } |
예제
#include <algorithm> #include <array> #include <iostream> int main() { std::array<int, 9> v {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto is_even = [](int i) { return i % 2 == 0; }; std::cout.setf(std::ios_base::boolalpha); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::partition(v.begin(), v.end(), is_even); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::reverse(v.begin(), v.end()); std::cout << std::is_partitioned(v.cbegin(), v.cend(), is_even) << ' '; std::cout << std::is_partitioned(v.crbegin(), v.crend(), is_even) << '\n'; }
출력:
false true false true
참고 항목
|
원소 범위를 두 그룹으로 분할합니다
(함수 템플릿) |
|
|
(C++11)
|
분할된 범위의 분할 지점을 찾습니다
(함수 템플릿) |
|
(C++20)
|
주어진 조건자에 의해 범위가 분할되었는지 확인합니다
(알고리즘 함수 객체) |