samedi 22 août 2015

Move all elements which satisfy some condition from one container to another, i.e. I'm looking for some kind of "move_if"

Given

std::vector<T> first = /* some given data */, second;

I want to move all elements e which satisfy some condition cond(e) from first to second, i.e. something like

move_if(std::make_move_iterator(first.begin()),
    std::make_move_iterator(first.end()),
    std::back_inserter(second), [&](T const& e)
{
        return cond(e);
});

I wasn't able to establish this with the algorithms library. So, how can I do that?

Aucun commentaire:

Enregistrer un commentaire