Let’s have simplified class:
class A
{
bool val_;
public:
A() : val_(true) {}
bool isNew() const { return val_; }
void setDirty() { val_ = false; }
};
and the vector of objects of such class:
vector<A> coll;
coll.push_back(A());
coll.push_back(A());
coll.push_back(A());
coll.push_back(A());
coll[1].setDirty();
coll[3].setDirty();
I need some elegant solution to rearrange(sort) elements in the vector, so that not modified objects will be grouped at the beginning of the sequence.
You can use Partition algorithm from standard library for that:
Or, as Christian Rau suggested solution without separate function: