std::stable_partition
The function `std::stable_partition` is part of the C++ Standard Library, specifically within the `<algorithm>` header. It rearranges the elements in a given range based on a specified predicate, ensuring that the relative order of equivalent elements is preserved. This means that if two elements are considered equal by the predicate, their original order in the input range will be maintained in the output.
This function is particularly useful when you need to group elements while keeping their original sequence intact. For example, if you have a list of numbers and want to separate even and odd numbers, `std::stable_partition` will do this without disrupting the order of the even or odd numbers within their respective groups.