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))

```
How about `sort`:

```
#include <algorithm>

std::sort(coll.begin(), coll.end(),
     [](const A & a, const A & b) -> bool { return a.isNew() < b.isNew(); } );

```

You'll have to rewrite the class to declare `isNew()` as `const`.

For older compilers, use a function instead of the lambda:

```
bool isNewCompare(const A & a, const A & b) { return a.isNew() < b.isNew(); }
std::sort(coll.begin(), coll.end(), isNewCompare);

```

*Edit:* @Vladimir has the better answer, `std::partition()` is the more appropriate algorithm for this problem.