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/']
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.
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.