Partition
In this lesson, we will study different algorithms that partition a range or help in the partitioning of a range.
ℹ️ What is a partition?
A partition of a set is a decomposition of a set into subsets such that each element of the set is precisely in one subset. The subsets are defined in C++ by a unary predicate so that the members of the first subset fulfill the predicate. The remaining elements are in the second subset.
C++ offers a few functions for dealing with partitions. All of them need a unary predicate pre
. std::partition
and std::stable_partition
take as input a predicate and a range and partition it according to the predicate and return the partition point. With std::partition_point
we can get the partition point of a partition. Afterwards we can check the partition with std::is_partitioned
or copy it with std::partition_copy
.
std::is_partitioned
: Checks if the range is partitioned.
Get hands-on with 1200+ tech skills courses.