ambs (22) [Avatar] Offline
It seems that partition and remove_if does the same (almost). While the first puts the 'interesting' elements in th beginning of the list, the second puts the 'interesting' at the end. If I am reading this correctly, this reference might be relevant.

Also, if I am correct, the next question will be: can we use partition to erase?

people.erase(people.begin(), std::partition(people.begin(), people.end(), is_not_female));


people.erase(std::remove_if(people.begin(), people.end(), is_not_female), people.end());

I know this might be just curiosity of a reader (me), but probably other readers will ask the same.
Ivan Cukic (97) [Avatar] Offline
There is an important difference, even if the algorithms do seem similar - `remove_if` leaves those elements that should be removed in an unspecified state, with the requirement they are destructible.

The `partition` algorithm keeps all the values valid. This means that `remove_if` will be generally be faster than `partition` (it can do moves instead of swaps).

It is an interesting question, but I'd say it is a bit out of the scope for the book. Maybe a blog post about that would be beneficial.

ambs (22) [Avatar] Offline
Understood. That 'elements are kept in a unspecified state' was understood as "the order is not relevant" by me.

And sure, some details are better not to be written in the book.
But in some situations (not this one, specifically) you can have two level of reading with some footnotes (for eager readers).

Looking forward for next chapters smilie