[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/algorithm/partition_point [Back]  [Original]

std::partition_point cppreference.com
cppreference.com

std::partition_point

cppreference.com

<metanoindex/>

 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++20)
, ranges::copy, ranges::sort, ...
(C++17)
(C++11)(C++11)(C++11)
(C++17)
(C++11)
( )
(C++11)
/
(C++11)
(C++17)

(C++17)
(C++17)
(C++17)
C
 
<tbody> </tbody>
template< class ForwardIt, class UnaryPredicate > ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p);
(1) ( C++11)
( std::partition) [first, last) , , p last , p.
:
Examines the partitioned (as if by std::partition) range [first, last) and locates the end of the first partition, that is, the first element that does not satisfy p or last if last if all elements satisfy p.
Google.
. .

first, last
:
the partitioned range of elements to examine
Google.
. .
p , true
,
:
for the elements found in the beginning of the range
Google.
. .
.

:

bool pred(const Type &a);

const & , .
Type , ForwardIt Type.

-
ForwardIt ForwardIterator.

[first, last) last, p.
:
The iterator past the end of the first partition within [first, last) or last if all elements satisfy p.
Google.
. .

first last
:
Logarithmic in the distance between first and last
Google.
. .

#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>

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::partition(v.begin(), v.end(), is_even);

    auto p = std::partition_point(v.begin(), v.end(), is_even);

    std::cout << "Before partition:\n    ";
    std::copy(v.begin(), p, std::ostream_iterator<int>(std::cout, " "));
    std::cout << "\nAfter partition:\n    ";
    std::copy(p, v.end(), std::ostream_iterator<int>(std::cout, " "));
}

:

Before partition:
    8 2 6 4
After partition:
    5 3 7 1 9

.

(C++11)
,
( ) []

Web Proxy Viewer  |  New URL  |  Original Page