I would like to partition a vector of references to MyObject (i.e. vector<MyObject*>) into 2 or more sub-vectors based on some common traits.
I have an equivalence function bool belongToSameGroup(MyObject *x, MyObject *y); which is true if certain data fields of MyObject are equal, and false otherwise. Because this equivalence is not general and for a particular purpose only, I’d prefer not to overload operator==.
What is the best way I can create, say, a vector of <vector<MyObject*>‘s (i.e. vector< vector<MyObject*> >) such that the elements are grouped based on their eqivalence under the function belongToSameGroup? I’d prefer not to do a bunch of for loops and to utilize STL algorithms and containers as much as possible.
I think
std::partitionis what you want. (Hey, it’s even in the title of your question!)