Partition
This algorithm allows us to divide or split ranges into separate sets.
ℹ️ What is a partition?
A partition of a set is a decomposition of a set in subsets so 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
partition a range and returns the partition point. With std::partition_point
you can get the partition point of a partition. Afterwards you can check the partition with std::is_partitioned
or copy it with std::partition_copy
.
Checks if the range is partitioned: