Пространства имён
Варианты
Действия

std::partition_point

Материал из cppreference.com

 
 
Алгоритмы
Функции
Немодифицирующие линейные операции
Модифицирующие линейные операции
Разделение
stable_partition
partition_point(C++11)
Сортировка (на отсортированных промежутках)
Бинарный поиск (на отсортированных промежутках)
Множества (на отсортированных промежутках)
Куча
Минимум/максимум
Числовые операции
Библиотека C
 
Заголовочный файл <algorithm>
template< class ForwardIt, class UnaryPredicate >
ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p);
(1) (начиная с C++11)
Рассматривает на разделы (как бы std::partition) диапазон [first, last) и находит конце первого раздела, то есть первый элемент, который не удовлетворяет p или last если в прошлом случае, если все элементы удовлетворяют p.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

first, last -
распределяли диапазон элементов для изучения
Original:
the partitioned range of elements to examine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - унарный предикат, который возвращает ​true
для элементов, найденных в начале диапазона
Original:
for the elements found in the beginning of the range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

Сигнатура функции-предиката должны быть эквивалентна следующей:

bool pred(const Type &a);

В сигнатуре не обязательно наличие const &, но функция не должна изменять переданный ей объект.
Тип Type должен быть таков, что объект типа ForwardIt может быть разыменован и затем неявно преобразован в Type. ​

Требования, накладываемые на типы
-
ForwardIt должен соответствовать требованиям ForwardIterator.

[править] Возвращаемое значение

Итератор прошлом концу первого раздела в [first, last) или last, если все элементы удовлетворяют p.
Original:
The iterator past the end of the first partition within [first, last) or last if all elements satisfy p.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Сложность

Логарифмическая в расстоянии между first и last
Original:
Logarithmic in the distance between first and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

#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)
проверяет, является ли диапазон отсортированы в порядке возрастания
Original:
checks whether a range is sorted into ascending order
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(шаблон функции) [edit]