std::ranges:: partition_point
std::ranges
| Non-modifying sequence operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Modifying sequence operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Partitioning operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Sorting operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Binary search operations (on sorted ranges) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Set operations (on sorted ranges) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Heap operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Minimum/maximum operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Permutation operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Fold operations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Operations on uninitialized storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더에 정의됨
<algorithm>
|
||
|
호출 서명
|
||
|
template
<
std::
forward_iterator
I,
std::
sentinel_for
<
I
>
S,
class
Proj
=
std::
identity
,
|
(1) | (C++20 이후) |
|
template
<
ranges::
forward_range
R,
class
Proj
=
std::
identity
,
|
(2) | (C++20 이후) |
분할된(마치
ranges::partition
에 의해 처리된 것처럼) 범위
[
first
,
last
)
또는
r
를 검사하고 첫 번째 파티션의 끝, 즉
pred
를 만족하지 않는 투영된 요소 또는 모든 투영된 요소가
pred
를 만족하는 경우
last
를 찾습니다.
이 페이지에서 설명하는 함수형 개체들은 algorithm function objects (일반적으로 niebloids 로 알려진)입니다. 즉:
- 명시적 템플릿 인수 목록은 이들 중 어느 것을 호출할 때도 지정할 수 없습니다.
- 이들 중 어느 것도 인수 의존 이름 검색 에 보이지 않습니다.
- 이들 중 어느 것이 함수 호출 연산자의 왼쪽에 있는 이름으로 일반 비한정 이름 검색 에 의해 발견될 때, 인수 의존 이름 검색 이 억제됩니다.
목차 |
매개변수
| first, last | - | 부분적으로 정렬된 범위 를 정의하는 반복자-감시자 쌍 |
| r | - | 검사할 부분적으로 정렬된 범위 |
| pred | - | 투영된 요소들에 적용할 조건자 |
| proj | - | 요소들에 적용할 투영 |
반환값
[
first
,
last
)
범위 내 첫 번째 파티션의 끝 바로 다음 반복자,
또는 모든 투영된 요소가
pred
를 만족하는 경우
last
와 동일한 반복자.
복잡도
주어진 N = ranges:: distance ( first, last ) 에 대해, 술어 pred 와 투영 proj 의 O(log N) 회 적용을 수행합니다.
그러나 센티넬이 std:: sized_sentinel_for < I > 를 모델링하지 않는 경우, 반복자 증감 횟수는 O(N) 입니다.
참고 사항
이 알고리즘은
ranges::lower_bound
의 보다 일반화된 형태로,
ranges::partition_point
와 다음 조건자를 사용하여 표현할 수 있습니다:
[
&
]
(
auto
const
&
e
)
{
return
std::
invoke
(
pred, e, value
)
;
}
)
;
.
예제
#include <algorithm> #include <array> #include <iostream> #include <iterator> auto print_seq = [](auto rem, auto first, auto last) { for (std::cout << rem; first != last; std::cout << *first++ << ' ') {} std::cout << '\n'; }; int main() { std::array v {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto is_even = [](int i) { return i % 2 == 0; }; std::ranges::partition(v, is_even); print_seq("After partitioning, v: ", v.cbegin(), v.cend()); const auto pp = std::ranges::partition_point(v, is_even); const auto i = std::ranges::distance(v.cbegin(), pp); std::cout << "Partition point is at " << i << "; v[" << i << "] = " << *pp << '\n'; print_seq("First partition (all even elements): ", v.cbegin(), pp); print_seq("Second partition (all odd elements): ", pp, v.cend()); }
가능한 출력:
After partitioning, v: 2 4 6 8 5 3 7 1 9 Partition point is at 4; v[4] = 5 First partition (all even elements): 2 4 6 8 Second partition (all odd elements): 5 3 7 1 9
참고 항목
|
(C++20)
|
범위가 오름차순으로 정렬되었는지 확인합니다
(알고리즘 함수 객체) |
|
(C++20)
|
주어진 값보다
작지 않은
첫 번째 요소에 대한 반복자를 반환합니다
(알고리즘 함수 객체) |
|
(C++11)
|
분할된 범위의 분할 지점을 찾습니다
(함수 템플릿) |