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.
['https://Stackoverflow.com/questions/7718418', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/801620/']
You can use [Partition](http://www.cplusplus.com/reference/algorithm/partition/) algorithm from standard library for that:

```
bool MyPredicate(A& a) { return a.isNew();}
...
// bound is iterator pointing to the first element for which predicate returns false
vector<A>::iterator bound = partition(coll.begin(), coll.end(), MyPredicate);

```

Or, as Christian Rau suggested solution without separate function:

```
std::partition(coll.begin(), coll.end(), std::mem_fun_ref(&A::isNew))

```
You could use `std::sort` from `<algorithm>` together with `boost::bind`. It could look something like this:

```
std::sort(coll.begin(), coll.end(), boost::bind(&A::isDirty, _1));

```

Assuming `A` has a function `bool A::isDirty() const`.

This works because you use the following ordering predicate implicitly:

```
bool cmp(const A &a, const A &b) {
    return a.isDirty();
}

```

We just don't care what happens when both are dirty or both are not dirty.